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

How mysql deletes tables in a database

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

Share

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

Editor to share with you mysql how to delete tables in the database, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Basic grammar

When you need to delete a table, you can use the DROP TABLE statement to do so. The syntax format is as follows:

DROP TABLE [IF EXISTS] [,]...

The syntax is as follows:

The name of the table that was deleted The DROP TABLE statement can delete multiple tables at the same time, and the user must have permission for the command.

When a table is deleted, all table data and table definitions are canceled, so be careful when using this statement.

When a table is deleted, the user's permissions on the table are not automatically deleted.

The parameter IF EXISTS is used to determine whether the deleted table exists before deletion. After this parameter is added, if the table does not exist, the SQL statement can be executed smoothly, but a warning will be issued (warning).

Delete the table select the database test_db that creates the table, create the tb_emp3 data table, enter the SQL statement and run the result as shown below.

Mysql > USE test_db;Database changedmysql > 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)

Delete the data table tb_emp3, enter the SQL statement and run the result as shown below.

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)

As can be seen from the execution result, the table named tb_emp3 no longer exists in the datasheet list of the test_db database, and the delete operation was successful.

This is how mysql deletes all the contents of the tables in the database. Thank you for 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!

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: 0

*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