IDENTITY_INSERT is set to OFF - How to turn it ON?

前端 未结 7 1364
-上瘾入骨i
-上瘾入骨i 2020-12-12 18:05

I have a deleted file archive database that stores the ID of the file that was deleted, I want the admin to be able to restore the file (as well as the same ID for linking

7条回答
  •  粉色の甜心
    2020-12-12 18:33

    Shouldn't you be setting identity_Insert ON, inserting the records and then turning it back off?

    Like this:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    SET IDENTITY_INSERT tbl_content ON
    GO
    
    ALTER procedure [dbo].[spInsertDeletedIntoTBLContent]
    @ContentID int, 
    SET IDENTITY_INSERT tbl_content ON
    ...insert command...
    SET IDENTITY_INSERT tbl_content OFF
    

提交回复
热议问题