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 to delete tables in a database

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to delete tables in the database, the article is very detailed, has a certain reference value, interested friends must read it!

In a database, you can delete one or more data tables using the DROP TABLE statement, with the syntax DROP TABLE [IF EXISTS] tablename1 [ , tablename2, tablename3...] ", where"IF EXISTS"is used to determine whether a data table exists before deleting it.

Operating environment of this tutorial: Windows 7 system, MySQL8 version, Dell G3 computer.

In MySQL databases, tables that are no longer needed can be deleted from the database.

You can drop one or more data tables using the DROP TABLE statement in the following syntax:

DROP TABLE [IF EXISTS] Table name 1 [ , Table name 2, Table name 3...]

Description:

IF EXISTS: Used to determine whether a data table exists before deleting it. If IF EXISTS is not added, MySQL will prompt an error when the data table does not exist and interrupt the execution of the SQL statement; if IF EXISTS is added, the SQL statement can be executed smoothly when the data table does not exist, but a warning will be issued.

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

At the same time as deleting the table, the structure of the table and all the data in the table will be deleted, so it is best to backup before deleting the data table, so as not to cause irreparable damage.

(Recommended tutorial: mysql video tutorial)

Examples:

First look at the data tables in the test_db database

mysql> USE test_db;Database changedmysql> SHOW TABLES;+--------------------+| Tables_in_test_db |+--------------------+| tb_emp1 || tb_emp2 || tb_emp3 || tb_emp3 |+--------------------+4 rows in set (0.00 sec)

Dropping a data table using the DROP TABLE statement

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

The execution result shows that the table named tb_emp3 no longer exists in the data table list of test_db database, and the deletion operation is successful.

The above is "database how to delete tables" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to 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

Database

Wechat

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

12
Report