How to Use database-level triggers SQL Server


show more Using database-level triggers provides you with in-depth training on Business. Taught by Martin Guidry as part of the SQL Server: Triggers, Stored Procedures, and Functions show less
please wait ...

Using database-level triggers

The triggers we've seen thus far are all at the table level, meaning they react to an INSERT, UPDATE, or DELETE statement issued to one table. SQL Server also supports triggers at the database level. These trigger fire whenever a statement is issued that would change the structure of that database. I have an example staged for you in your exercise files. This trigger we're saying is on the database on line 2, so that means it applies to the entire database.

Line 3 says it is for any attempt to drop a table or any attempt to alter a table. The body of the trigger is very simple. It's going to PRINT a message say you do not have permission to drop or alter to the table and then is going to ROLLBACK. In other word it's going to undo whatever someone was attempting to do. So I'll execute this, and now we can find these triggers under the Programmability menu. We have a folder called Database Triggers. If I refresh that, I see the new trigger I just created.

So let's go ah...

Using database-level triggers
Video duration: 1m 57s 1h 52m Advanced

Viewers:

Using database-level triggers provides you with in-depth training on Business. Taught by Martin Guidry as part of the SQL Server: Triggers, Stored Procedures, and Functions

Subjects:
Business Developer IT
Software:
SQL Server
Author:
please wait ...