您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

sql delete 语句用法介绍

2024/6/25 11:53:24发布47次查看
delete 语句用于删除表中的行,这种删除理论上来是不是可恢复的,但是经过一些高级的处理还是可以恢复数据的,不过比较麻烦了。
语法
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' );
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product