Extended Events - Capture TRUNCATE using object_altered event

  • I am trying to capture TRUNCATEs using the object_altered event using Extended Events but with out success.

    With the TRUNCATE being a DDL statement I thought the object_altered would have captured it? - is this not posible?

  • I would use something like this:

    CREATE EVENT SESSION [truncate] ON SERVER

    ADD EVENT sqlserver.sp_statement_starting(SET collect_statement=(1)

    WHERE ([sqlserver].[like_i_sql_unicode_string]([statement],N'truncate table%'))),

    ADD EVENT sqlserver.sql_statement_starting(SET collect_statement=(1)

    WHERE ([sqlserver].[like_i_sql_unicode_string]([statement],N'truncate table%')))

  • Thanks - yes I have tried that and it works.
    I just thought the TRUNCATE would be captured as an ALTER TABLE event?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply