Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IGNORING FOREIGN KEYS
Message
 
To
05/12/2000 16:07:03
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00449631
Message ID:
00449637
Views:
8
>I am writing a script to place initialized rows into a database that has be completed as far as the creation of all my foreign key (FK)relationships are concerned. Unfortunately some of the initial table rows will not be able to be entered unless I take certain FKs out, then place the data in, then reset the FKs to the tables again. Is there a way in that I can have the program disregard the Foreign Keys (without dropping and re-creating the tables without the foreign keys) so that I can get the rows in I need, and then easily turn on the referential integrity again. Once the rows are in the integrity will be o.k.

In your script, can you not:

1. Drop the FK constraint
2. Import the data
3. Recreate the FK constraint

With something like this:

IF OBJECT_ID('dbo.FK_ImportTypeID') IS NOT NULL
ALTER TABLE Import
DROP CONSTRAINT FK_ImportTypeID

/*
Data import routine here
/*

ALTER TABLE Import
ADD CONSTRAINT FK_ImportTypeID FOREIGN KEY (ImportTypeID) REFERENCES ImportType(ImportTypeID)
Chris McCandless
Red Sky Software
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform