Get the App
SLTechnology News&Howtos  ›  Database  › 

How to delete tables in a database

Shulou Source: shulou.com Published: 2022-05-31 22:55:33 09月21日 Update

This article mainly introduces how to delete tables in the database, the article is very detailed, has a certain reference value, interested friends must read it!

In a database, you can delete one or more data tables using the DROP TABLE statement, with the syntax DROP TABLE [IF EXISTS] tablename1 [ , tablename2, tablename3...] ", where"IF EXISTS"is used to determine whether a data table exists before deleting it.

Operating environment of this tutorial: Windows 7 system, MySQL8 version, Dell G3 computer.

In MySQL databases, tables that are no longer needed can be deleted from the database.

You can drop one or more data tables using the DROP TABLE statement in the following syntax:

DROP TABLE [IF EXISTS] Table name 1 [ , Table name 2, Table name 3...]

Description:

IF EXISTS: Used to determine whether a data table exists before deleting it. If IF EXISTS is not added, MySQL will prompt an error when the data table does not exist and interrupt the execution of the SQL statement; if IF EXISTS is added, the SQL statement can be executed smoothly when the data table does not exist, but a warning will be issued.

When a table is deleted, user permissions on the table are not automatically deleted.

At the same time as deleting the table, the structure of the table and all the data in the table will be deleted, so it is best to backup before deleting the data table, so as not to cause irreparable damage.

(Recommended tutorial: mysql video tutorial)

Examples:

First look at the data tables in the test_db database

mysql> USE test_db;Database changedmysql> SHOW TABLES;+--------------------+| Tables_in_test_db |+--------------------+| tb_emp1 || tb_emp2 || tb_emp3 || tb_emp3 |+--------------------+4 rows in set (0.00 sec)

Dropping a data table using the DROP TABLE statement

mysql> DROP TABLE tb_emp3;Query OK, 0 rows affected (0.22 sec)mysql> SHOW TABLES;+--------------------+| Tables_in_test_db |+--------------------+| tb_emp1 || tb_emp2 || tb_emp3 |+--------------------+3 rows in set (0.00 sec)

The execution result shows that the table named tb_emp3 no longer exists in the data table list of test_db database, and the deletion operation is successful.

The above is "database how to delete tables" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Data datasheets databases statements tutorials content multiple articles grammar success value interest at the same time name backup buddy partner loss more best Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Microsoft Xiaomi vpn