How do you check if IDENTITY_INSERT is set to ON or OFF in SQL Server?

前端 未结 8 973
暗喜
暗喜 2020-12-09 00:52

I\'ve searched for this, but threads in which it appeared tended to have answers from people who didn\'t understand the question.

Take the following syntax:

<
8条回答
  •  情歌与酒
    2020-12-09 01:15

    Very good question. I Have same issue. May be you can try to reset IDENTITY_INSERT using TRY/CATCH? For example, you make the job but not sure if the job is finished and IDENTITY_INSERT is set to OFF.

    Why you don't try:

    BEGIN TRY 
    ...
    END TRY 
    BEGIN CATCH
    SET IDENTITY_INSERT table OFF;
    END CATCH;
    

    Also I am not sure that this is working correctly but I see that adding only SET IDENTITY_INSERT ... OFF did not return error. So you can set just in case in the end SET IDENTITY_INSERT ... OFF.

提交回复
热议问题