Home  >  Article  >  Database  >  A simple comparison of DELETE and DROP in SQL

A simple comparison of DELETE and DROP in SQL

青灯夜游
青灯夜游Original
2019-01-15 10:32:2011723browse

In SQL commands, DELETE and DROP are both elements that can be used to delete the database, so what is the difference between them? The following article will give you a brief comparison of DELETE and DROP, and introduce the differences between DELETE and DROP. I hope it will be helpful to you.

A simple comparison of DELETE and DROP in SQL

A brief introduction to the DELETE command

DELETE is a data manipulation language (DDL) command. You can use the DELETE command to delete some or all records from a table. Can be used with the WHERE clause to delete certain records that meet the added requirements; if the WHERE condition is not specified, all records will be deleted. [Recommended related video tutorials: MySQL Tutorial]

Note: The entire table, domain, or constraint cannot be deleted using the DELETE command.

The syntax of the DELETE command is as follows:

DELETE FROM relation_name  where条件;

If you link two tables using a foreign key and delete tuples from the referenced table, the referencing table will also be automatically deleted to maintain referential integrity.

A brief introduction to the DROP command

DROP is a data definition language (DDL) command that can delete one or more items from the database table, it will delete all related data, indexes, triggers, constraints and permission specifications of the table

The syntax of the DROP command is as follows:

DROP SCHEMA schema_name RESTRICT;
DROP Table table_name CASCADE;

There are two DROP commands Behavior options named CASCADE and RESTRICT. When CASCADE is used in DROP schema, it removes all related elements like schema, fields and all tables in constraints.

When we use CASCADE to delete a table from the schema, it deletes all constraints, views, and elements that reference the relationship being deleted.

Note: The table referenced by any foreign key constraint cannot be deleted.

The main difference between DELETE and DROP

1. DELETE is a data manipulation language command, while DROP is a data definition language Order.

2. The DELETE command is used to delete some or all tuples from the table. However, the DROP command is used to delete one or more tables from the database. It can delete all related data, indexes, triggers, constraints and permission specifications of the table.

3. DELETE can be used with the WHERE clause, but DROP cannot be used with any command.

4. You can use the DELETE command to perform a rollback operation because it uses a buffer; but you cannot operate a rollback operation when using the DROP command because it directly processes the actual data. .

5. Since the DELETE command does not delete the table, it will not release any space; the drop command will delete the entire table, thereby releasing memory space.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of A simple comparison of DELETE and DROP in SQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What is a DBMSNext article:What is a DBMS