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.
Rollback database modifications - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Rollback database modifications
With DDL triggers, database developers can create a system that will prevent structural changes from being made to a table. Let's take a look by creating a new trigger called PreventTableAlterations. I'm going to scope this to the current database which will be the KinetEcoTRG database. So I'll say ON DATABASE on line number five. Then I want to target just ALTER_TABLE commands that are sent to this database. So on line six, we say FOR ALTER_TABLE. Then after the AS command, we have the different commands that I want the trigger to execute. The first one is just a simple PRINT statement. We'll print the line, "A trigger is cancelling all ALTER_TABLE statements." Then we'll issue the ROLLBACK command to roll back the transaction and undo any changes that the original ALTER_TABLE statement was trying to do. Let's go ahead and create this trigger on the KinetEcoTRG database, and now we can test it out. First, we'll create a new table called dbo.People. It's just going to have a single…
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.