SQL Server中TRUNCATE事务回滚操作方法
李应升诫子书,英文爱情诗,真人娱乐选官方288x
我们一般都认为truncate是一种不可回滚的操作,它会删除表中的所有数据以及重置identity列。
如果你在事务中进行truncate操作,就能回滚。反之,它就不会从日志文件文件恢复数据。它不会在日志文件中记录删除的那些数据,它只在日志中记录数据页的单元分配。
下面的例子就能解释上面的所说的.
use temp_test_database
go
--创建一个临时表
create table truncatetabel(id int)
insert into truncatetabel(id)
select 1
union all
select 2
union all
select 3
go
--检查插入的数据
select * from truncatetabel
如图:
开始执行事务
--开始事务
begin tran
truncate table truncatetabel
go
--回滚之前检查truncatetable
select * from truncatetabel
go
f5执行,如图:
执行回滚事务
--回滚事务
rollback tran
go
再次检查表truncatetable
--回滚之后再次检查truncatetable
select * from truncatetabel
go
f5执行,如图:
总结一下,事务是可以对truncate操作进行回滚的。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
-
网友评论