Failed insert query
- From: postings@xxxxxxxxxxxxxxx
- Date: 4 Aug 2005 04:32:18 -0700
Hi
I'm trying to port some data from one database table to another
database table on the same server.
This is the query I am using:
----->
INSERT into newdatabase.dbo.contactevents (EventTypeID, UserID,
ContactID, DateEntered, EventDate, Description)
select '20','1', ContactID, '1/1/2005 00:00', '1/1/2005 00:00',
ISNULL(Notes,'')
from olddatabase.dbo.contactevents
WHERE Exists (SELECT ContactID FROM newdatabase.dbo.contacts)
<-------
This is the error I'm getting:
----->
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_ContactEvents_Contacts'. The conflict occurred in database
'newdatabase', table 'Contacts', column 'ContactID'.
The statement has been terminated.
<-------
There is a relationship between the contacts table (Primary key
ContactID) and the contactsevent (foreign key ContactID) table. I guess
the error being flagged up here is that some contacts don't exist in
the new database, therefore referential intergretory won't allow it
being copied. I thought I could get around this using:
"WHERE Exists (SELECT ContactID FROM newdatabase.dbo.contacts)"
Note I've also tried:
"WHERE Exists (SELECT * FROM newdatabase.dbo.contacts)"
What am I doing wrong?
Many Thanks!
Alex
.
- Follow-Ups:
- Re: Failed insert query
- From: Chandra
- Re: Failed insert query
- From: Simon Hayes
- Re: Failed insert query
- Prev by Date: Line 1: Incorrect syntax near '='
- Next by Date: Re: Line 1: Incorrect syntax near '='
- Previous by thread: Line 1: Incorrect syntax near '='
- Next by thread: Re: Failed insert query
- Index(es):
Relevant Pages
|