Update values in identity column

前端 未结 5 668
执笔经年
执笔经年 2020-12-08 02:26

How do I override the identity column in MSSQL? I tried :

    SET IDENTITY_INSERT GeoCountry ON
    UPDATE GeoCountry SET CountryID = 18 WHERE C         


        
5条回答
  •  [愿得一人]
    2020-12-08 03:20

    You could also do this in one statement using delete into, this has the benefit of eliminating any error copying/moving the row data, for example

    set identity_insert [dbo].[MyTableName] on
    
    delete from [dbo].[MyTableName]
    output 
    ,
    [deleted].[Col1], 
    [deleted].[Col2], 
    [deleted].[Col3], 
    into 
    [dbo].[MyTableName] (
    [IdColumnName], 
    [Col1], 
    [Col2], 
    [Col3])
    where
    [IdColumnName]=
    
    set identity_insert [dbo].[MyTableName] off
    

提交回复
热议问题