Home > Database > SQL > body text

What are the differences between delete and truncate

青灯夜游
Release: 2019-06-17 15:31:04
Original
42748 people have browsed it

In SQL, both the delete command and the truncate command can be used to delete data (records), so what are the differences between them? The following article will introduce to you the difference between the delete command and the truncate command. I hope it will be helpful to you.

What are the differences between delete and truncate

The difference between delete and truncate commands

1. Command type

delete is a data manipulation language (DML) command; and truncate is a data definition language (DDL) command.

2. Function

The delete command deletes single, multiple or all records from the table according to the specified SQL statement; while the truncate command deletes all records and table structures from the database.

3. Where clause

The delete command supports the WHERE clause. You can use the where clause with DELETE to filter and delete specific records; however, the truncate command does not support the WHERE clause.

4. Locking

The delete command uses row-level locking, and each row in the table is locked for deletion; the truncate command uses table-level locking, locking the entire table to delete all records.

5. Index view

The delete command can be used with index views; however, the truncate command cannot be used with index views.

6. Execution speed

Because the delete command maintains the log, the speed is very slow. However, since the truncate command maintains minimal logging records in the transaction log, it executes faster.

7. Table structure

The delete command will not affect the table structure, while the truncate command will delete the table structure from the database.

8. Transaction space

The delete command uses more transaction space than the truncate command.

The above is the detailed content of What are the differences between delete and truncate. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template