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 ...

Get SQL Server® 2008 Administration: Real World Skills for MCITP Certification and Beyond now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.