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.

Writing data from the EVENTDATA() function

Writing data from the EVENTDATA() function - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Writing data from the EVENTDATA() function

Let's take a look at what the EVENTDATA function returns by writing the contents to a table. In the last movie, we reviewed all of the elements returned when SQL Server executes a CREATE_TABLE statement. First, I'm going to create a table that has a column for each of these elements. The table that I'll create is called TableEventCapture. And here, we can see the different columns that I'm about to create. We have one that corresponds to each row being returned from the XML table. So here's EventType, PostTime, SPID, and so on. Each of these I'll store as an nvarchar 100 data type, except for the TSQL command, which needs to be a little bit longer, so I'll save that out as an nvarchar 2000. Let's highlight lines one through 17 and execute them to create that table. And now we can turn our attention to creating the trigger that will fill in rows of data into that table. So I'll create a trigger called TableCreateEvent. It's going to be on my database for all CREATE_TABLE events. Then…

Contents