您的位置:首页 > 数据库

sql的delete删除和事务

2015-07-30 14:11 489 查看
一般都是 delete from table where table.字段 = ...

如果table使用别名,则应该:

DELETE a from (

select *,ROW_NUMBER() over(PARTITION by empid order by empid) as rn from b_emp ) a where rn = 1

这句话还包含了一个去重复的功能。

如果在sqlserver中使用增删改的功能,需要rollback或者commit的话,需要先开启事务。否则不在事务中的话 是不能rollback的

begin tran
DELETE a from (
select *,ROW_NUMBER() over(PARTITION by empid order by empid) as rn from b_emp ) a where rn = 1

rollback;
commit;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: