drop table is a command used in the database to delete one or more data tables. The specific format is "DROP TABLE [IF EXISTS] table name list"; if you want to delete multiple tables at the same time, just change the table name Write them one after another, separated by commas.
(Recommended tutorial: mysql video tutorial)
In the MySQL database, for data tables that are no longer needed , we can delete it from the database.
When deleting a table, the table structure and all data in the table will be deleted, so it is best to back up the data table before deleting it to avoid irreparable losses.
In the database, you can use the DROP TABLE
statement to delete one or more data tables. The syntax format is as follows:
DROP TABLE [IF EXISTS] 表名列表
For the syntax format The description is as follows:
Table name list: Indicates the name of the data table to be deleted. DROP TABLE can delete multiple tables at the same time. Just write the table names at the end and separate them with commas. For example: Table name 1, Table name 2, Table name 3...
.
IF EXISTS: used to determine whether the table exists before deleting the data table. If IF EXISTS is not added, MySQL will prompt an error and interrupt the execution of the SQL statement when the data table does not exist; after adding IF EXISTS, when the data table does not exist, the SQL statement can be executed smoothly, but a warning will be issued.
Note:
The user must have the permission to execute the DROP TABLE command, otherwise the data table will not be deleted.
When a table is deleted, the user's permissions on the table will not be automatically deleted.
Example:
View the data table
mysql> SHOW TABLES; +--------------------+ | Tables_in_test_db | +--------------------+ | tb_emp1 | | tb_emp2 | | tb_emp3 | +--------------------+ 3 rows in set (0.00 sec)
It can be seen from the running results that there are There are three data tables: tb_emp1, tb_emp2 and tb_emp3.
Let’s delete the data table tb_emp3. The input SQL statement and running results are as follows:
mysql> DROP TABLE tb_emp3; Query OK, 0 rows affected (0.22 sec) mysql> SHOW TABLES; +--------------------+ | Tables_in_test_db | +--------------------+ | tb_emp1 | | tb_emp2 | +--------------------+ 2 rows in set (0.00 sec)
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of What is the command of drop table?. For more information, please follow other related articles on the PHP Chinese website!