SQL Server self-increment ID inserts the specified data
SET IDENTITY_INSERT table name on--allows inserting the specified data into the self-increment column Id INSERT INTO table_name (ID,NAME) VALUES (1, ' Test ') set IDENTITY_INSERT table name off--close Inserts the specified data for the self-increment column ID
Attention:
1.set Identity_insert is only valid for the current session.
2.set identity_insert table name on set, you must display the specified ID or insert an error. If INSERT into table_name values (' 111 ') will be an error.
Inserts the specified value to the self-increment ID. Error: "Cannot insert an explicit value for the Identity column in table" When IDENTITY_INSERT is set to OFF.
The INSERT statement does not display the specified ID. Error: "You can specify an explicit value for the identity column in the table only if the column list is used and Identity_insert is on."
Category: SQL Server
SQL Server self-increment ID inserts the specified data