The method of deleting multiple tables in batch by mysql
Editor to share with you mysql batch delete multiple tables of the method, I believe that most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Mysql batch delete multiple table method: use the "DROP TABLE" statement, as long as the table names are written after each other, separated by commas; syntax format "DROP TABLE [IF EXISTS] table name 1 [, table name 2, table name 3.]".
Mysql deletes multiple tables in batch
Use the DROP TABLE statement to delete one or more data tables in the following syntax format:
DROP TABLE [IF EXISTS] Table name 1 [, Table name 2, Table name 3.]
The syntax format is described as follows:
Table name 1, table name 2, table name 3. Represents the name of the data table to be deleted. DROP TABLE can delete multiple tables at the same time, as long as the table names are written after each other and separated by commas.
IF EXISTS is used to determine whether a data table exists before it is deleted. Without IF EXISTS, MySQL will prompt an error when the data table does not exist and interrupt the execution of the SQL statement; with IF EXISTS, the SQL statement can be executed smoothly when the data table does not exist, but will issue a warning (warning).
Two points to note:
The user must have permission to execute the DROP TABLE command, or the data table will not be deleted.
When a table is deleted, the user's permissions on the table are not automatically deleted.
Example:
Query the data table in the database
Mysql > SHOW TABLES;+-+ | Tables_in_test_db | +-+ | tb_emp1 | | tb_emp2 | | tb_emp3 | +-+ 2 rows in set (0.00 sec)
From the running results, we can see that there are three data tables of tb_emp1, tb_emp2 and tb_emp3 in the database.
Let's delete the data tables tb_emp1 and tb_emp3. The SQL statement entered and the run result are as follows:
Mysql > DROP TABLE tb_emp1,tb_emp3;Query OK, 0 rows affected (0.22 sec) mysql > SHOW TABLES;+-+ | Tables_in_test_db | +-+ | tb_emp2 | +-+ 1 rows in set (0.00 sec)
As can be seen from the execution result, the tables named tb_emp1 and tb_emp3 no longer exist in the datasheet list of the test_db database, and the delete operation was successful.
The above are all the contents of mysql's method of deleting multiple tables in batches. Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!