SQL Server EventData () function to get DDL trigger information _mssql

Source: Internet
Author: User
Tags rollback
Copy Code code as follows:

--Create a log table
CREATE TABLE triggerlog (loginfo XML)

--Create a dummy table to delete later on
CREATE TABLE tabletodelete (Id int PRIMARY KEY)

--Create a new table as a delete test table
INSERT into Tabletodelete VALUES (1)
Go

--Creates a drop Table's DDL
CREATE TRIGGER Stoptabledrop on DATABASE after drop_table
As
DECLARE @EventData as XML
SET @EventData = EventData ()--The DDL information must be intercepted before rollback
ROLLBACK
PRINT ' DROP TABLE attempt in database ' + db_name () + '. '
INSERT into Triggerlog VALUES (@EventData)

Perform the following delete operation:
DROP TABLE Tabletodelete
Triggers the above DDL, thereby rolling back the operation.
Execute the following sql:
SELECT * from Triggerlog
View the DDL information just intercepted.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.