In the database, you can use the "DROP TABLE" statement to delete one or more data tables. The specific syntax is "DROP TABLE [IF EXISTS] table name 1 [ , table name 2, table name 3 ... ]", where "IF EXISTS" is used to determine whether the table exists before deleting the data table.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In the MySQL database, we can delete the data tables from the database that are no longer needed.
You can use the DROP TABLE
statement to delete one or more data tables. The syntax format is as follows:
DROP TABLE [IF EXISTS] 表名1 [ ,表名2, 表名3 ...]
Instructions:
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.
When a table is deleted, the user's permissions on the table will not be automatically deleted.
When deleting a table, the structure of the table and all the data in the table will be deleted. Therefore, it is best to back up the data table before deleting it to avoid irreparable losses.
(Recommended tutorial: mysql video tutorial)
Example:
First check the test_db database Data table
mysql> USE test_db; Database changed mysql> SHOW TABLES; +--------------------+ | Tables_in_test_db | +--------------------+ | tb_emp1 | | tb_emp2 | | tb_emp3 | | tb_emp3 | +--------------------+ 4 rows in set (0.00 sec)
Use the DROP TABLE
statement to delete the data table
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 can be seen that the name tb_emp3 no longer exists in the data table list of the test_db database. table, the delete operation was successful.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How to delete table from database. For more information, please follow other related articles on the PHP Chinese website!