在事务中截断表 [英] Truncate Table Within Transaction

查看:28
本文介绍了在事务中截断表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在事务中使用 SQLtruncate table"命令吗?我正在创建一个应用程序,我的表有大量记录.我想删除所有记录,但如果应用程序失败,我将回滚我的交易.删除每条记录需要很长时间.我想知道如果我使用 truncate table,我是否仍然可以回滚事务并在发生故障时取回我的数据.我意识到截断表不会将每个删除写入事务日志,但我想知道它是否将页面释放写入日志以便回滚工作.

Can the SQL "truncate table" command be used within a transaction? I am creating an app and my table has a ton of records. I want to delete all the records, but if the app fails I was to rollback my transaction. Deleting each record takes a very long time. I'm wondering if I use truncate table, can I still rollback the transaction and get my data back in the event of a failure. I realize that truncate table doesn't write each delete to the transaction log, but I'm wondering if it writes the page deallocation to the log so that rollback works.

推荐答案

在 SQL Server 中,您可以从事务中回滚 TRUNCATE.正如您所提到的,它确实将页面释放写入日志.

In SQL Server, you can rollback a TRUNCATE from a transaction. It does write page deallocation to the log, as you mentioned.

这篇关于在事务中截断表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆