语法
delete from 表名称 where 列名称 = 值
国外网站参考
代码如下 复制代码
the sql delete command has the following generic sql syntax:
delete from table1
where some_column = some_value
如果你跳过的sql where子句执行delete语句表达时,然后在指定的表的所有数据将被删除。下面的sql语句会从客户表中删除所有的数据和我们?l升完全空表:
代码如下 复制代码
delete from table1
如果您指定一个where子句在您的sql delete语句,只符合标准将被删除表中的行:
代码如下 复制代码
delete from customers
where lastname = 'smith'
删除更多
您也可以执行更复杂的删除。
您可能希望基于另一个表中的值的一个表中删除记录。既然你不能from子句中列出多个表中,当您执行删除,您可以使用exists子句
for example:
代码如下 复制代码
delete from suppliers
where exists
( customers.name
from customers
where customers.customer_id = suppliers.supplier_id
and customers.customer_name = 'ibm' );
这将在供应商表,其中有一个客户表的名称是ibm,customer_id是相同的supplier_id记录中删除所有记录。
了解exists的条件。
如果你想确定将被删除的行的数目,您可以运行下面的sql语句,在执行删除之前。
代码如下 复制代码
select count(*) from suppliers
where exists
( select customers.name
from customers
where customers.customer_id = suppliers.supplier_id
and customers.customer_name = 'ibm' );
