T-SQL Throw Exception

前端 未结 6 1360
孤独总比滥情好
孤独总比滥情好 2020-12-29 01:13

I am facing the famous \'Incorrect syntax\' while using a THROW statement in a T-SQL stored procedure. I have Googled it and checked the questions on StackOverf

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 01:34

    To solve your problem,

    Incorrect statement near 'THROW'. Expecting CONVERSATION, DIALOG, DISTRIBUTED, or TRANSACTION

    put semi-colon before your throw statement:

    BEGIN
        ;THROW 99001, 'O associated with the given Q Id already exists', 1;
    END
    

    And about the

    "Incorrect statement near 'THROW'".

    Try to use this in case you're using a older version than SQL 2012:

    RAISERROR('O associated with the given Q Id already exists',16,1);
    

    Because THROW is a new feature of SQL 2012.

提交回复
热议问题