For faster navigation, this Iframe is preloading the Wikiwand page for 删除 (SQL).

删除 (SQL)

SQL裡,DELETE语句用于从表中删除一个或多个数据。使用它需要定义一个子集作为条件,否则表中的所有数据都会被删除。

用法

[编辑]

DELETE 语句的一半语法为:

DELETE FROM 表名 [WHERE 条件]

该语句能够使表中所有满足WHERE子句条件的元组都会被删除。如果缺少 WHERE 子句,则表中所有的元组都会被删除。

执行一条 DELETE 语法能够触发触发器而在其他表中执行删除操作。例如,有相联系的两个表,如果作为被参照关系的表中的元组被删除,则作为参照关系的表也会被删除,以保证关系的参照完整性

示例

[编辑]
  • 从表 pies中删除flavorLemon Meringue的元组:
DELETE FROM pies WHERE flavor='Lemon Meringue';
  • 从表trees中删除height低于80的元组.
DELETE FROM trees WHERE height < 80;
  • 删除表mytable中所有的元组:
DELETE FROM mytable;
  • 删除表 mytable中符合子查询结果的元组:
DELETE FROM mytable WHERE id IN (SELECT id FROM mytable2)

参考

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
删除 (SQL)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?