TRUNCATE TABLE
[{database_name. [schema_name]. | | schema_name . schema_name. } ] }]
table_name
[; ] This TRUNCATE command will redistribute the page containing the data in the table, and all of that data will be erased completely after execution. In terms of speed, TRUNCATE is much faster than DELETE based on the amount of information stored in the Transaction Log section, and also so if certain records are accidentally deleted, it will not be recoverable. . In essence, TRUNCATE is a Data Definition Language operator - DDL, which also means that we need to have at least ALTER TABLE or higher permissions to perform. But the TRUNCATE TABLE decentralization does not exist. If a data table after executing TRUNCATE has the function of increasing the number of columns, it will automatically be rearranged according to the original definition. In addition, there are some limitations with the TRUNCATE syntax, and cannot be applied on specific tables like the situation below:
- When the data table is referenced by Index View.
- External links are shortened.
- That data sheet is used for copying.
- The table belongs to the database being logged.
When to use
Depending on the specific situation, please use the DELETE or TRUNCATE command accordingly. In it, DELETE syntax is used quite widely and popularly because it allows users to clearly identify which record to delete, combined with JOINS command and some other parameters. Blocking is possible when we use DELETE to delete a large amount of data, so users need to be extremely careful when manipulating. On the other hand, the TRUNCATE command will help the administrator delete an entire data table simply and quickly.
Good luck!