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.

Triggers on CREATE, ALTER, or DROP

Triggers on CREATE, ALTER, or DROP - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Triggers on CREATE, ALTER, or DROP

The triggers that we've looked at so far have been examples of DML triggers, ones that are fired based off of INSERT, UPDATE, and DELETE commands that manipulate data in a table. Now, let's turn our attention to DDL triggers. Data definition language triggers are fired by CREATE, ALTER, DROP, GRANT, REVOKE, or DENY commands that are used to define the structure of a database and work with security permissions. The scope of these triggers will apply to either the current database or the current server. In the CREATE TRIGGER command, you'll specify the scope with the ON clause. For trigger scope to the current database, you'll use ON DATABASE. And for trigger scope to the entire server, use ON ALL SERVER. Next, we need to define when the trigger will fire. For our DML triggers, we did this with the AFTER or INSTEAD OF arguments. For instance, AFTER INSERT or INSTEAD OF DELETE. In DDL triggers, we use the FOR clause. After that, we can choose from literally hundreds of different possible…

Contents