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的
如果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;
相关文章推荐
- 数据库 - 第一范式(1NF)
- 查询和删除数据表中重复数据的sql
- [转载]Oracle中TO_DATE格式
- nginx+memcached+tomcat集群 session共享完整版
- Navicat For Mysql快捷键
- 【未测试】采用Atlas+Keepalived实现MySQL读写分离、读负载均衡
- 【对比mysql各种代理】mysql中间件研究(Atlas奇虎360,cobar阿里巴巴,TDDL淘宝分布式数据层)
- mysql TIMESTAMP(时间戳)详解
- sqlplus导入dmp数据库文件
- linux下安装mongodb
- 案例(用封装的ajax加载数据库的数据到页面)
- Oracle用户、角色、授权和表空间
- sql中in和exists的区别效率问题
- 【未测试】使用mysql-proxy 快速实现mysql 集群 读写分离
- 常用人脸数据库
- SQL基础总结——20150730
- Oracle中的COALESCE,NVL,NVL2,NULLIF函数
- oracle中执行计划中的cardinality
- mysql导入数据错误
- MySQL函数