What is wrong with my Try Catch in T-SQL?

后端 未结 6 649
轻奢々
轻奢々 2020-12-16 15:19

I am using SQL Server 2008 and when I run this Statement in Management studio the Select statement in the Catch Block is executed as expected

BEGIN TRY
 INSE         


        
6条回答
  •  情话喂你
    2020-12-16 15:43

    Workaround with dynamic sql. Maybe it will be helpful for someone.

    begin try
        exec('
            insert into IDontExist(ProductID)
            values(1)
        ')
    end try
    begin catch
        select 'There was an error! ' + error_message()
    end catch
    

提交回复
热议问题