Home > Database > Mysql Tutorial > body text

How to delete table in mysql

青灯夜游
Release: 2023-01-06 11:17:20
Original
17769 people have browsed it

In mysql, you can use the "DORP TABLE" statement to delete a data table. The general syntax format is "DROP TABLE table_name;"; among them, "table_name" represents the name of the data table to be deleted, and you can specify multiple data table names, as long as they are separated by commas.

How to delete table in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Deleting a data table in MySQL is very easy, but you must be very careful when deleting a table, because all data will disappear after executing the delete command.

The following is the general syntax for deleting a MySQL data table:

DROP TABLE table_name ;
Copy after login

table_name: 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.

Example:

First check the data table in the test_db database

mysql> USE test_db;
Database changed

mysql> SHOW TABLES;
+--------------------+
| Tables_in_test_db  |
+--------------------+
| tb_emp1            |
| tb_emp2            |
| tb_emp3            |
+--------------------+
3 rows in set (0.00 sec)
Copy after login

If you want to delete the data table tb_emp2

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

As you can see from the execution results, the table named tb_emp2 no longer exists in the data table list of the test_db database, and the deletion operation was successful.

Related free learning recommendations: mysql video tutorial

The above is the detailed content of How to delete table in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The 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.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template