Getting error in create Trigger

  • use [Test3]

    GO

    create trigger tr on Emp

    for update

    as

    select * from inserted;

    when i execute it i am getting this error

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'GO'.

    Msg 111, Level 15, State 1, Line 1

    'CREATE TRIGGER' must be the first statement in a query batch.

    Please help me

    Thanks

    Mahendra singh rajpurohit

  • mahenpali (9/30/2009)


    use [Test3]

    GO

    create trigger tr on Emp

    for update

    as

    select * from inserted;

    when i execute it i am getting this error

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'GO'.

    Msg 111, Level 15, State 1, Line 1

    'CREATE TRIGGER' must be the first statement in a query batch.

    Please help me

    Thanks

    Mahendra singh rajpurohit

    Self explanatory! Just dont use the USE DB and Go rather just select the database and run the below script:

    create trigger tr on Emp

    for update

    as

    select * from inserted;

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

  • Just out of curiosity.....

    What are you doing with this trigger by the way..?

  • It should work just fine as a script with the GO provided that GO starts in column 1. You cannot, however, do something of this nature in a stored procedure or dynamic SQL because you cannot use GO in either of those.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I think I came across something alike in the past. It turned out that after GO, newline was encoded 'unix style' with one character only (0x0A) instead of the sequence 0x0A 0x0D. Just out of curiosity, can you open your script in a hex editor and see what is going on?

    Regards

    Piotr

    ...and your only reply is slàinte mhath

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply