Sqlsever specifies the explicit value for the ID column. Most of them are in two tables with the same structure. One Table inserts data with the specified conditions in the other table, and the following error is reported:
Only when the column list is used and IDENTITY_INSERT is ON can an explicit value be specified for the ID column in the '*' table.
I found a solution on the Internet and tried it myself.
I. The problem is detailed as follows:
System: windows2003
Database: 2005
Database instances: wzgl2004 and wzgl2003. Both instances have the kc table.
Execution statement
Insert into wzgl2004.dbo. kc select * from wzgl2003.dbo. kc
There is an error message:
"Only when the list of columns is used and IDENTITY_INSERT is ON can you specify an explicit value for the ID column in 'wzgl2004. dbo. kc 'of the table. "
Ii. solution:
Copy codeThe Code is as follows:
SET IDENTITY_INSERT test ON
Insert into wzgl2004.dbo. kc (id, name) select (id, name) from wzgl2003.dbo. kc
SET IDENTITY_INSERT test OFF
Iii. SET IDENTITY_INSERT help knowledge
1. SET IDENTITY_INSERT: allows explicit values to be inserted into the table's ID column.
2. Syntax
SET IDENTITY_INSERT [database. [owner.] {table} {ON | OFF}
Parameters
Database
Is the name of the database where the specified table resides.
Owner
Is the name of the table owner.
Table
Is the name of the table containing the ID column.
3. Attaching: at any time, the IDENTITY_INSERT attribute of only one table in the session can be set to ON. If a table has SET this attribute to ON and sends a SET IDENTITY_INSERT ON statement to the other table®SQL Server™An error message is returned, indicating that SET IDENTITY_INSERT has been SET to ON and that this attribute has been SET to ON. If the inserted value is greater than the current table id value, SQL Server automatically uses the new value as the current ID value.
SET IDENTITY_INSERT is SET during execution or running, rather than during analysis.
Sqlsever specifies the explicit value for the identification column to end here. If you have any questions, please contact us at www.cnc.com.cn. China Information Port provides you with an efficient and secure SQL database.