DDL, DML and the ghost

George Menoutis 21 Reputation points
2021-05-20T10:18:36.17+00:00

I know that TRUNCATE TABLE cannot be caught by delete triggers. From what I've read, it is considered a DDL statement.

What is very interesting is that it does not even appear in sys.sys.trigger_event_types, which means it cannot even be caught on db/server-level triggers.

Is that really so? Why, of all possible statements, only truncate is untriggerable?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,799 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CathyJi-MSFT 22,201 Reputation points Microsoft Vendor
    2021-05-21T09:53:18.067+00:00

    Hi @George Menoutis ,

    > Why, of all possible statements, only truncate is untriggerable?

    Quote from MS document TRUNCATE TABLE (Transact-SQL).

    Although a TRUNCATE TABLE statement is in effect a DELETE statement, it doesn't activate a trigger because the operation doesn't log individual row deletions.

    Quote from the blog Difference between SQL Truncate and SQL Delete statements in SQL Server.

    98547-screenshot-2021-05-21-175032.jpg


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.