O'Reilly logo

SQL Server® 2008 Administration: Real World Skills for MCITP Certification and Beyond by Tom Carpenter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Triggers

Triggers are created using the CREATE TRIGGER T-SQL command. A trigger is ultimately a collection of one or more lines of T-SQL code, so a GUI tool for the creation of triggers is really not practical. The good news is that the syntax used is rather simple. The following syntax is used for trigger creation:

CREATE TRIGGER trigger_name
    ON { table | view | database | all server}
    WITH dml_trigger_option>
    { FOR | AFTER | INSTEAD OF } { event }
    AS
    Insert T-SQL code starting here;

Like most CREATE statements, the first thing you do with CREATE TRIGGER is specify a name. Next, you should indicate the trigger level of table, view, database, or server. If the trigger level is a database, table, or view, you specify ON object_name ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required