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

Delete commands in T-SQL (drop, truncate, and delete)

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

Share

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

1. DROP command:

Syntax:

Drop table datasheet-deleting the entire table (including table structure definitions) is the fastest and most thorough, without saving specific logs (deleting content and definitions, freeing up space. Is to remove the whole table.), it is basically impossible to recover.

2. TRUNCATE command:

Syntax:

Truncate table data Table-Delete the contents of the entire table (only delete data and retain the table structure). If you do not save the specific delete log, it will truncate the data and free up space.

3. DELETE command:

Syntax:

Delete table data Table where condition-deleting content does not delete the definition and does not free up space. A log of each deletion operation is logged, deleted one by one, and a log of each deletion operation is recorded.

Summary:

Drop command: delete fast, do not retain the table structure, can only delete the whole table.

Truncate command: fast delete, retain the table structure, can only delete all the data of the entire table, using less system and transaction log resources.

Delete command: delete slowly, delete one row at a time, delete part of the data, and record an item for each row deleted in the transaction log, you can roll back the delete operation, which is used more frequently.

1. Truncate is very fast on all kinds of watches, big ones and small ones. If there is a ROLLBACK command, Delete will be undone, but truncate will not be undone.

2. Truncate is a DDL language, and like all other DDL languages, it will be implicitly submitted and cannot use the ROLLBACK command on truncate.

3. Truncate will reset the high level and all indexes. When fully browsing the entire table and index, the table after truncate operation is much faster than the table after Delete operation.

4. Truncate cannot trigger any Delete triggers.

5. When the table is emptied, the table and the index of the table will be reset to the initial size, while delete cannot.

6. Cannot empty the parent table

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