Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of the drop table command in mysql

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the use of the drop table command in mysql, which can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

Drop table is a command used to delete one or more tables in the database in the format of "DROP TABLE [IF EXISTS] list of table names"; if you want to delete multiple tables at the same time, simply write the table names after each other and separate them with commas.

In the MySQL database, we can delete tables from the database that are no longer needed.

When deleting the table, the structure of the table and all the data in the table will be deleted, so it is best to back up the data table before deleting it, so as to avoid irreparable losses.

In the database, you can use the DROP TABLE statement to delete one or more data tables in the following syntax format:

DROP TABLE [IF EXISTS] list of table names

The syntax format is described as follows:

List of table names: 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, separated by commas, for example: table name 1, table name 2, table name 3.

IF EXISTS: 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).

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:

View the data sheet

Mysql > SHOW TABLES;+-+ | Tables_in_test_db | +-+ | tb_emp1 | | tb_emp2 | | tb_emp3 | +-+ 3 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 test_tb database.

Let's delete the data table tb_emp3. The SQL statement entered and the run result are as follows:

Mysql > DROP TABLE tb_emp3;Query OK, 0 rows affected (0.22 sec) mysql > SHOW TABLES +-+ | Tables_in_test_db | +-+ | tb_emp1 | | tb_emp2 | +-+ 2 rows in set (0.00 sec) Thank you for reading this article carefully I hope the editor can share the content of the drop table command in mysql to help you. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 301

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report