Professional Web Applications Themes

CREATE TRIGGER syntax - Microsoft SQL / MS SQL Server

What is the difference between FOR and AFTER in the CREATE TRIGGER SYNTAX? CREATE TRIGGER trigger_name ON { table | view } [ WITH ENCRYPTION ] { { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] } [ WITH APPEND ] [ NOT FOR TION ] AS [ { IF UPDATE ( column ) [ { AND | OR } UPDATE ( column ) ] [ ...n ] | IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask ) { comparison_operator } column_bitmask [ ...n ] } ] sql_statement [ ...

  1. #1

    Default CREATE TRIGGER syntax

    What is the difference between FOR and AFTER in the CREATE TRIGGER SYNTAX?

    CREATE TRIGGER trigger_name
    ON { table | view }
    [ WITH ENCRYPTION ]
    {
    { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] }
    [ WITH APPEND ]
    [ NOT FOR TION ]
    AS
    [ { IF UPDATE ( column )
    [ { AND | OR } UPDATE ( column ) ]
    [ ...n ]
    | IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask )
    { comparison_operator } column_bitmask [ ...n ]
    } ]
    sql_statement [ ...n ]
    }
    }

    But BOL states that AFTER is the default, if only FOR is specified? Does
    that mean that they are the same thing?

    TIA,
    Ted.




    Ted Guest

  2. #2

    Default Re: CREATE TRIGGER syntax

    They are the same thing. FOR is there for backward compatibility.

    --
    Tom

    ---------------------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinnaclepublishing.com/sql


    "Ted" <com> wrote in message news:phx.gbl...
    What is the difference between FOR and AFTER in the CREATE TRIGGER SYNTAX?

    CREATE TRIGGER trigger_name
    ON { table | view }
    [ WITH ENCRYPTION ]
    {
    { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] }
    [ WITH APPEND ]
    [ NOT FOR TION ]
    AS
    [ { IF UPDATE ( column )
    [ { AND | OR } UPDATE ( column ) ]
    [ ...n ]
    | IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask )
    { comparison_operator } column_bitmask [ ...n ]
    } ]
    sql_statement [ ...n ]
    }
    }

    But BOL states that AFTER is the default, if only FOR is specified? Does
    that mean that they are the same thing?

    TIA,
    Ted.





    Tom Guest

  3. #3

    Default Re: CREATE TRIGGER syntax

    Ted,

    FOR is interpreted as AFTER. Once there were only AFTER triggers, so FOR
    was the keyword used to introduce which actions (insert, update, delete),

    Now that there are two types of trigger, you specify AFTER or INSTEAD OF.
    It is better to be explicit IMHO.

    Russell Fields
    "Ted" <com> wrote in message
    news:phx.gbl... 


    Russell Guest

  4. #4

    Default Re: CREATE TRIGGER syntax

    Thanks guys.

    "Ted" <com> wrote in message
    news:phx.gbl... 


    Ted Guest

Similar Threads

  1. pl/pgsql trigger: syntax error at or near "ELSEIF"
    By Roman Neuhauser in forum PostgreSQL / PGSQL
    Replies: 3
    Last Post: January 14th, 04:24 PM
  2. CREATE TRIGGER
    By Stephen in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: August 20th, 07:56 AM
  3. CREATE TRIGGER [testtrigger] ON *
    By Marc Fauser in forum Microsoft SQL / MS SQL Server
    Replies: 9
    Last Post: July 11th, 06:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139