Home > Database > Mysql Tutorial > In SQL language, what is the command to delete a table?

In SQL language, what is the command to delete a table?

青灯夜游
Release: 2020-11-30 16:10:44
Original
48924 people have browsed it

In SQL language, the command to delete a table is "DROP", and the specific syntax format is "DROP TABLE [IF EXISTS] table name". The "DROP TABLE" command can delete multiple tables at the same time. Just write the table names at the end and separate them with commas.

In SQL language, what is the command to delete a table?

(Recommended tutorial: mysql video tutorial)

In SQL language, the command to delete a table is () .

A. DELETE

B. DROP

C. CLEAR

D. REMOVE

Answer: B. DROP

Answer analysis

In SQL language, the command to create a table is CREATE, the command to modify the table is ALTER, and the command to delete a table is It is DROP. In addition, the insertion, deletion and query commands of data in the table are INSERT, UPDATE and SELECT respectively.

Extended information:

In the MySQL database, for data tables that are no longer needed, we can delete them 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.

Use the DROP TABLE statement to delete one or more data tables. The syntax format is as follows:

DROP TABLE [IF EXISTS] 表名
Copy after login

The syntax format is explained as follows:

  • 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.

  • IF EXISTS is used to determine whether the table exists before deleting it. 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.

Two points to 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:

mysql> SHOW TABLES;
+--------------------+
| Tables_in_test_db  |
+--------------------+
| tb_emp2            |
| tb_emp3            |
+--------------------+
2 rows in set (0.00 sec)

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 login

The execution result shows 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.

For more programming-related knowledge, please visit: Programming Courses! !

The above is the detailed content of In SQL language, what is the command to delete a table?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
sql
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