From the course: Complete Guide to Advanced SQL Server
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Solution: Create a DDL trigger - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Solution: Create a DDL trigger
Let's walk through how I would approach the challenge of writing information about all table-level DDL events to a logging table, or what I like to call an EventCapture table. So the first thing I need to do on this script is just jump into and make sure we're using the KinetEcoTRG database. And then I have a comment here that outlines our objective. So we're going to pull information out of the EVENTDATA function, and the information that we're interested in is the EventType, UserName, ObjectName, and TSQL command. So the first thing that I need to do is create a table that will hold all of this information that comes out of this function. So we can start by writing a CREATE_TABLE statement. And I'm going to call this table ChallengeTwoEventCapture. You can call your table whatever you'd like, as long as it doesn't conflict with the table that we already have inside of the KinetEco database over here. So let's add in our columns. Now, I'm going to add in a couple of columns that I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.