Please help me to create a insert query (error of foreign key constrant)
Posted
by Rajesh Rolen- DotNet Developer
on Stack Overflow
See other posts from Stack Overflow
or by Rajesh Rolen- DotNet Developer
Published on 2010-04-29T10:50:38Z
Indexed on
2010/04/29
10:57 UTC
Read the original article
Hit count: 349
I want to move data from one database's table to another database's table its giving me foreign key error. please tell me how can i insert all those data which is valid except those rows who have error of foreign key. i am using sql server 2005
My query is :
SET IDENTITY_INSERT City ON
INSERT INTO City ([cityid],[city],[country],[state],[cityinfo]
,[enabled],[countryid],[citycode],[stateid],[latitude],[longitude])
SELECT [cityid],[city],[country],[state],[cityinfo]
,[enabled],[countryid],[citycode],[stateid],[latitude],[longitude]
FROM TD.DBo.City
getting this error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__city__countryid__3E52440B". The conflict occurred in database "schoolHigher", table "dbo.country", column 'countryId'.
please tell how can i move those data whose foreign key is valid.
© Stack Overflow or respective owner