Re: INSERT INTO with FOREIGN KEY ???
- From: "Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom>
- Date: Thu, 4 May 2006 00:37:05 +0100
I can't figure out how to manage INSERT INTO in a table having FOREIGN KEY
constraint.
Well if you have FK constraint, you must make sure items exist _FIRST_ on
the FK table before inserting your table.
We have FKs on a SQL Server database.
When inserting data into tables, we have to make sure that they are
populated in the right order so that FKs are not triggered.
The same is true for DELETE but it is now in reverse order.
And if you have a recordset where you are doing INSERTs and DELETEs then you
are in trouble as
You need 2 recordsets, an empty one for INSERTs and a different one for
DELETEs (or use Command/Connection Execute). But basically you want to do
DELETE table
DELETE FK table
'UPDATES here
INSERT FK table
INSERT table
in that order so that FK constraints are alsways satisfied. Triggers are
worth looking at if you want cascaded INSERTs, DELETEs
Stephen Howe
.
- Follow-Ups:
- References:
- INSERT INTO with FOREIGN KEY ???
- From: .
- INSERT INTO with FOREIGN KEY ???
- Prev by Date: INSERT INTO with FOREIGN KEY ???
- Next by Date: Re: INSERT INTO with FOREIGN KEY ???
- Previous by thread: INSERT INTO with FOREIGN KEY ???
- Next by thread: Re: INSERT INTO with FOREIGN KEY ???
- Index(es):
Relevant Pages
|
|