[Reprinted] the difference between the delete table and the truncate table is tabletruncate.
The general syntax format for deleting data using the delete statement:
Delete [from]
{Table_name, view_name}
[Where]
Delete all row data in the XS table
Delete XS
After the execution, we found that the data in the XS table was deleted, but the table structure was still there.
Truncate
The truncate table statement deletes all the data in the specified table. Therefore, it is also called the clear table data statement. The general format is as follows:
Truncate table name
Because the truncate statement will delete all data in the table and cannot be recovered, you must be very careful when using it.
The truncate table is used to delete all rows in the specified table, but the table structure, its columns, constraints, and indexes remain unchanged. The Count value used for the new row ID is reset to the initial value of the column. If you want to retain the ID Count value, use the DELETE statement.
The truncate table is faster than the DELETE block and uses less system and transaction log resources. The DELETE statement deletes a row at a time and records one row in the transaction log. The truncate table deletes data by releasing the data pages used to store TABLE data, and only records the release of pages in transaction logs.
For tables referenced by foreign key constraints, you cannot use truncate table to DELETE data. Instead, you should use the DELETE statement of the WHERE clause of the bag. In addition, the truncate table cannot be used for tables that participate in the index view.