set identity_insert 表名 ON --允許對自增列Id插入指定數據 insert into table_name(Id,Name) values(1,'test') set identity_insert 表名 OFF --關閉對自增列Id插入指定數據
注意:
1.set identity_insert只對當前會話生效。
2.set identity_insert 表名 ON 設置后,必須顯示指定Id,否則插入錯誤。如insert into table_name values('111')將報錯。
向自增ID插入指定值。 報錯:“當 IDENTITY_INSERT 設置為 OFF 時,不能為表 ' ' 中的標識列插入顯式值”。
插入語句未顯示指定ID。 報錯:“僅當使用了列列表並且 IDENTITY_INSERT 為 ON 時,才能為表' '中的標識列指定顯式值”。