sql delete 关键字简介


一、sql delete 关键字功能简介

delete 关键字功能是清除表中指定的数据
delete 关键字通常和 where 关键字一起结合使用


二、 sql delete 关键字语法及使用说明

sql delete 关键字语法
2.1 delete [表名] where [条件]
2.2 delete from [表名] where [条件]
2.3 delete * from [表名] where [条件]


注意事项:
当不输入where 条件时,此时将清除表中全部数据
删除成功后,系统将返回所影响的行数


  
create table A(keyId int,info varchar(60), writeDate datetime)
insert into A values
(1,'a','2017-1-1'),(2,'b','2017-1-2'),(3,'c','2017-1-3'),
(11,'a','2017-2-1'),(12,'b','2017-2-2'),(13,'c','2017-2-3')
/*1 */
select * from A 
go
/*2 */
delete  A  where keyId =2 
select * from A 
go
/*3 */
delete  from A where keyId=3 
select * from A 
go
 
 /*4 不输入条件将清理所有数据*/
 delete from A 
 select * from A 
 go
truncate table A
drop table A 

相关阅读:
sql update 关键字简介
sql insert into 关键字简介及用法
sql order by 关键字用法
sql and or 关键字简介
sql where 关键字简介
sql select distinct top 关键字简介
sql select
sql简介
sql 删除重复数据
如果查询MSSQL中重复列(group by having count)