Home > Database > SQL > body text

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

coldplay.xixi
Release: 2020-08-19 14:42:32
Original
5859 people have browsed it

The difference between deleting table data and deleting table structure in SQL: 1. When deleting table data, the table structure is still there, while deleting table structure means deleting the entire table, including structure and data; 2. Command Different, delete table data [delete from table name], while delete table structure is [drop table table name].

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

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

1. Different definitions.

Deleting the contents of the table refers to deleting the data of the table. The structure of the table is still there.

Deleting the structure of a table means deleting the entire table, including structure and data.

2. The commands are different.

Delete table data:

truncate table table name;

or

delete from table name;

Delete table structure:

drop table table name;

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

Extended information:

truncate: Delete content, release space but do not delete definitions (retain the data structure of the table). Truncate cannot delete row data. To delete it, the table must be cleared.

delete: The delete statement is used to delete rows in the table. The deletion process of the delete statement is to delete one row from the table at a time, and at the same time, the deletion operation of the row is saved in the log as a transaction record for rollback operation.

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

If you want to retain the identity count value, please use delete instead. If you want to drop a table definition and its data, use the drop table statement.

drop: Delete content and definitions to free up space. To put it simply, remove the entire table. No new data can be added in the future unless a new table is added.

The drop statement will delete the constraints, triggers, and indexes that the table structure depends on; the stored procedures/functions that depend on the table will be retained, but their status will change For: invalid.

Related learning recommendations: SQL video tutorial

The above is the detailed content of What is the difference between deleting table data and deleting table structure in SQL?. 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