Mysql method to delete tables in the database: 1. Use the "USE database name;" statement to select and enter the database where the table needs to be deleted; 2. Use "DROP TABLE [IF EXISTS]
[ ,
,
…];” statement deletes one or more data tables in the database.
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. Let's take a look at how to delete data tables in the MySQL database.
Basic syntax
When you need to delete a table, you can use the DROP TABLE statement to complete it. The syntax format is as follows:
DROP TABLE [IF EXISTS] <表名1> [ , <表名2> , <表名3> …];Copy after loginThe syntax is as follows:
: The name of the deleted table. The DROP TABLE statement can delete multiple tables at the same time, and the user must have permission for this command.
When the table is deleted, all table data and table definitions will be canceled, so be careful when using this statement.
When a table is deleted, the user's permissions on the table will not be automatically deleted.
The parameter IF EXISTS is used to determine whether the deleted table exists before deletion. After adding this parameter, when deleting the table, if the table does not exist, the SQL statement can be executed smoothly. But a warning will be issued.
Note: 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. .
Example:
mysql> USE test_db; Database changed mysql> CREATE TABLE tb_emp3 -> ( -> id INT(11), -> name VARCHAR(25), -> deptId INT(11), -> salary FLOAT -> ); Query OK, 0 rows affected (0.27 sec) mysql> SHOW TABLES; +--------------------+ | Tables_in_test_db | +--------------------+ | tb_emp2 | | tb_emp3 | +--------------------+ 2 rows in set (0.00 sec)Copy after loginDelete 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_emp2 | +--------------------+ 1 rows in set (0.00 sec)Copy after loginThe execution results show that the table named tb_emp3 no longer exists in the data table list of the test_db database, and the deletion operation was successful.
The above is the detailed content of How to delete a table in the database in mysql. For more information, please follow other related articles on the PHP Chinese website!
Related labels:source:php.cnStatement of this WebsiteThe content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cnLatest Articles by Author
2020-01-15 11:18:13 2020-01-15 10:58:09 2020-01-15 10:34:39 2020-01-15 10:16:56 2020-09-14 10:58:08 2020-01-15 09:58:52 2020-01-15 09:36:25 2020-01-15 09:28:34 2020-01-15 09:22:01 2020-01-15 09:09:20Latest IssuesHow to group and count in MySQL? I'm trying to write a query that extracts the total number of undeleted messages sent to f...From 2024-04-06 18:30:1701353MySQL gets data from multiple tables I have a eg_design table which contains the following columns: and eg_domains table which ...From 2024-04-06 18:42:4402479Related TopicsMore>