惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
V
V2EX
S
Security Affairs
T
Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
IT之家
IT之家
J
Java Code Geeks
The Register - Security
The Register - Security
U
Unit 42
C
CERT Recently Published Vulnerability Notes
月光博客
月光博客
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Project Zero
Project Zero
S
Schneier on Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
博客园 - 司徒正美
V
Vulnerabilities – Threatpost
T
Tor Project blog
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
小众软件
小众软件
L
LangChain Blog
Attack and Defense Labs
Attack and Defense Labs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Palo Alto Networks Blog
A
Arctic Wolf
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 叶小钗
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 最新话题
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta

博客园 - 柏放

检测移动设备横竖屏 [转]一句css代码让你的网站变灰,一起悼念地震中逝去的生命! MYSQL命令行常用操作 MySQL数据库导入导出详解[转发] 国外达人收集的Cheet Sheet PHP学习:字符串操作和正则表达式 PHP学习:数组 PHP学习:文件操作 SQL Server:获得用户最新或前n条订单的几种SQL语句 SQL Server:APPLY表运算符 SQL Server:查询当前服务器有多少连接请求 SQL Server:关于Null的一些事 js倒计时 SQL Server:在Management Studio中使用Web浏览器 SQL Server:获得表的元数据 - SET FMTONLY ON 排序:插入排序及希尔排序 SQL Server:把CSV文件导入到SQL Server表中 SQL Server:使用一个语句块插入多条记录 Google Map API学习记录
SQL Server:在事务中回滚TRUNCATE操作
柏放 · 2010-03-13 · via 博客园 - 柏放

我们一般都认为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

如图:
truncate-table-1
开始执行事务

--开始事务
BEGIN TRAN
TRUNCATE TABLE TruncateTabel
GO
--回滚之前检查TruncateTable
SELECT * FROM TruncateTabel
GO
F5执行,如图:
truncate-table-2
执行回滚事务
--回滚事务
ROLLBACK TRAN
GO

再次检查表TruncateTable

--回滚之后再次检查TruncateTable
SELECT * FROM TruncateTabel
GO

F5执行,如图:
truncate-table-3

参考:http://blog.sqlauthority.com/2010/03/04/sql-server-rollback-truncate-command-in-transaction/

--EOF--

Author:兴百放
Web:http://xbf321.cnblogs.com/
Time:2010.3.12

posted on 2010-03-13 15:45  柏放  阅读(3520)  评论(2)    收藏  举报

刷新页面返回顶部