Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

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. When the trigger level is the server, you simply specify ALL SERVER.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial