📜  SQL 中 DELETE 和 DROP 的区别

📅  最后修改于: 2021-09-10 02:19:35             🧑  作者: Mango

先决条件 – SQL 命令
DELETE是一个数据操作语言 (DML) 命令,用于从关系中删除部分或全部元组。如果 WHERE 子句与 DELETE 命令一起使用,它只删除那些满足 WHERE 子句条件的元组,但如果 DELETE 语句中缺少 WHERE 子句,则默认情况下所有存在于关系中的元组都将被删除。

DELETE 命令的语法:

DELETE FROM relation_name 
WHERE condition;

DROP是一种数据定义语言 (DDL) 命令,它删除模式的命名元素,如关系、域或约束,您还可以使用 DROP 命令删除整个模式。

DROP 命令的语法:

DROP SCHEMA schema_name RESTRICT;
DROP Table table_name CASCADE;

对比图:

Parameter DELETE DROP
Basic It removes some or all the tuples from a table. It removes entire schema, table, domain, or constraints from the database.
Language Data Manipulation Language command Data Definition Language command.
Clause WHERE clause mainly used along with the DELETE command. No clause required along with DROP command.
Rollback Actions performed by DELETE can be rolled back as it uses buffer. Actions performed by DROP can’t be rolled back because it directly works on actual data.
Space space occupied by the table in the memory is not freed even if you delete all the tuples of the table using DELETE It frees the table space from memory
Main Issue Shortage of memory Memory fragmentation
Locality of reference Excellent Adequate
Flexibility Fixed size Resizing is possible