Why does truncate table put inside a transaction fail with ASE error 226?
4
votes
1
answer
2172
views
Spotted some answer excerpts on the question entitled "Why use both truncate and drop? ":
> "TRUNCATE is logged, and it can be rolled back.
...
Let me rebut these falsehoods. I am writing this rebuttal from a SQL Server perspective, but everything I say here should be equally applicable to Sybase." answered [Nov 8 '11 at 21:39](https://dba.stackexchange.com/a/7685/63644)
Attempted to add comment but original post has been protected hence this new Question as a workaround.
The above may be true for Microsoft SQL Server, it is NOT for Sybase - see ASE error 226 below
1> BEGIN TRAN
2> TRUNCATE TABLE xyz
3> go
Msg 226, Level 16, State 1:
Server 'ASE16', Line 2:
TRUNCATE TABLE command not allowed within multi-statement transaction.
1> ROLLBACK
2> go
Furthermore - I almost agree with the notion that truncate before drop should make no difference...
1. TRUNCATE TABLE on its own - involves some syslog activities (surprisingly)
2. DROP TABLE on its own (without proceeding truncate)
+ deallocate the table pages within an "empty" BEGIN/END Xacts pair
+ updates sysobject, sysindexes system tables & their indexes & such internally generated DMLs involve logging within BEGIN/END Xacts pair
DROP TABLE on its own is marginally better as table page deallocation is not logged while truncate on its own seems to incur small amount of logging surprisingly.
SYSLOG Audit Trail : truncate on its own (as shown below - TX seq is based on the most recent 5 transaction being displayed)
Log Record Type Op TX seq
---------------------------------------- -- -----------
======>Checkpoint Record 17 5
Begin Xact 0 5
Delete Extent Log Record 77 5
Direct Update/In Place Update 9 5
Update Record for DOL Table 65 5
End Xact 30 5
======>Checkpoint Record 17 4
SYSLOG Audit Trail : drop table on its own (as shown below - TX seq is based on the most recent 5 transaction being displayed)
Log Record Type Op TX seq
---------------------------------------- -- -----------
======>Checkpoint Record 17 5
Begin Xact 0 5
Delete Extent Log Record 77 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
Deallocate Data Page 21 5
B-Tree Non-Leaf Delete 72 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
Deallocate Data Page 21 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
B-Tree Non-Leaf Delete 72 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
Update Record for DOL Table 65 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
B-Tree Non-Leaf Delete 72 5
Delete Log Record for DOL Table 66 5
End Xact 30 5
Begin Xact 0 4
End Xact 30 4
======>Checkpoint Record 17 3
Asked by Raymond
(101 rep)
Sep 17, 2017, 12:47 PM
Last activity: Sep 20, 2017, 07:44 PM
Last activity: Sep 20, 2017, 07:44 PM