Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the difference between deleting table data and deleting table structure in SQL

Shulou Source: shulou.com Published: 2022-05-31 23:51:13 10月02日 Update

This article mainly introduces the SQL delete table data and delete table structure what is the difference, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

In SQL, delete table data and delete table structure: 1, delete table data, the table structure is still there, and delete table structure refers to delete the entire table, including structure and data; 2, different commands, delete table data [delete from table name], and delete table structure is [drop table table name].

The difference between deleting table data and deleting a table structure in SQL:

1. The definition is different.

To delete the contents of a table is to delete the data of the table. The structure of the watch is still there.

To delete the structure of a table is to delete the entire table, including structure and data.

2. Different orders.

Delete the data from the table:

Truncate table name

Or

Delete from name

Delete the table structure:

Drop table name

Extended data:

Truncate: delete the content, free up space without deleting the definition (preserve the data structure of the table). Truncate cannot delete row data. If you want to delete it, you have to empty the table.

The delete:delete statement is used to delete rows from a table. The delete statement performs deletions by deleting one row at a time from the table and saving the deletion of that row in the log as a transaction record for rollback operations.

Truncate and delete without where: delete only the data, not the table structure (definition).

If you want to keep the identity count value, use delete instead. Use the drop table statement if you want to delete the table definition and its data.

Drop: delete content and definitions to free up space. To put it simply, remove the whole watch. Data cannot be added in the future unless a new table is added.

The drop statement removes the constraints on which the structure of the table is dependent (constrain, trigger, index); stored procedures / functions that depend on the table will be retained, but their state will change to: invalid.

Thank you for reading this article carefully. I hope the article "what's the difference between deleting table data and deleting table structure in SQL" shared by the editor is helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Data structure different name article statement content at the same time command space procedure line transaction value interest function that is data structure log more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn OPPO Reno macOS Microsoft