SQL trigger on Truncate

15,108

Solution 1

From msdn:

TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.

Solution 2

You can't do this on SQL server.

From MSDN

TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. For more information, see CREATE TRIGGER (Transact-SQL).

Solution 3

Are you letting users run TRUNCATE TABLE ad hoc / willy nilly? If not, instead of worrying about using a trigger, why not wrap the TRUNCATE command in a stored procedure that also deals with whatever the trigger would have done after the truncate finished? (But you'd have to do it in the opposite order, of course.)

Share:
15,108
Sreedhar
Author by

Sreedhar

:-)

Updated on June 01, 2022

Comments

  • Sreedhar
    Sreedhar about 2 years

    How to Fire a trigger when you do TRUNCATE (instead deleted) in MSSQL