Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,
I want to copy from one databse table to other databse table. but i am getting this error .both are same tables .. but second table is empty.. i have delete all values now want to insert prom other databse. but i am getting this error

An explicit value for the identity column in table 'mydb..mytable' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Posted

hi try this..


SET IDENTITY_INSERT table1 ON
Insert into table1
select * from table2


this error is coming because you have identity column in your table inwhich you are inserting data from other.
 
Share this answer
 
Comments
Torakami 20-Jul-13 3:04am    
i tried .. same error
try this: first of set the identity column to "false" in the table1
and then run the script.
or post the complete columns of both tables. only a person can you a solution

SQL
Insert into db1.dbo.table1
select * from db2.dbo.table2
 
Share this answer
 
You should check with this:
MSDN : Keep Identity Values When Bulk Importing Data (SQL Server)[^]
Try this:
SQL
SET IDENTITY_INSERT Db1.dbo.[B] ON
insert into db1.dbo.[B]
select * from db2.dbo.[A] where reqid = 201
SET IDENTITY_INSERT db1.dbo.[B] OFF



--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900