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.

推荐答案

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

Sql相关问答推荐

Oracle SQL-将结果列在单行中

仅 for each 唯一ID返回一个元素,并仅返回最新连接的记录

获得第三名或最老的记录

如何隐藏聚合JSON数组元素的键

如何在SQL Server中统计按备注分组的记录数

将Dense_RANK列为聚合(非解析)函数(&A)

对多个条件的SQL进行排名

从给定数据中查找下一个工作日期

根据日期 Select ID 的上一条记录

聚合内部的条件在哪里?

根据标识符将两行合并为一行

对现有记录进行分组

将空 JSON 数组添加到 SQL Server 表列中的 JSON 字符串

带有数组输入参数的Snowflake UDF优化

在 SQL 中使用循环遍历按时间顺序排列的数据

使用 SAVE TRANSACTION 时 BEGIN 和 COMMIT 语句的数量不匹配

SQL 查询以填充单个列中的所有值

postgreSQL 中的循环表

如何比较同一张表中的行并进行相应更新

两个相似的 presto SQL 查询之间的差异