Failed insert query



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

.



Relevant Pages

  • Re: How do I show more than one contact type for a contact?
    ... You would need to add a new table to the database. ... It would hold the ContactID and the CategoryID. ... > hoping to tweak it to meet my needs. ...
    (microsoft.public.access.queries)
  • Re: database design question
    ... has projectID and ContactID fields in it. ... proper table design for the database. ... If I build separate tables for each contact role ...
    (microsoft.public.access.gettingstarted)
  • Re: Please help with If Then Else code
    ... | The database, ... | contactTBL and membershipTBL ... | membershipTBL - foreign key - contactID ... | <%Dim MyLogin ...
    (microsoft.public.frontpage.programming)
  • Re: Please help with If Then Else code
    ... | The database, ... | contactTBL and membershipTBL ... | membershipTBL - foreign key - contactID ... | <%Dim MyLogin ...
    (microsoft.public.frontpage.programming)
  • Re: Help with foreign keys
    ... one that uses a local Access 2007 database. ... UserID varCharNOT NULL FOREIGN KEY REFERENCES Users, ... So, if we have Customers, and Invoices tables, a left join would give us: ... REGARDLESS if the child records ...
    (microsoft.public.access.gettingstarted)