I'm trying to set up an import form live database to our development database.

I trying to do this using SSIS, but the import is failing because of constraints.

E.g. I have the following tables:

  • Customers
  • Products
  • OrderLines
  • Orders

Importing Customers and Products is fine, because they do not depend on anything. But when importing OrderLines it fails because the Order is not yet created.

How do I change the order of how SSIS imports tables?

Or maybe I'm not supposed to use foreign key constraints?

2 Answers 2


disable or remove the foreign key constraints before the data import & then enable or add them after the import eg. remove/add

alter table t1  DROP CONSTRAINT fk_1
alter table t1 WITH CHECK add constraint fk_1 foreign key (fk)
references t2 (i)


alter table t1 NOCHECK CONSTRAINT fk_1
alter table t1 WITH CHECK CHECK CONSTRAINT fk_1 

The WITH CHECK is important, otherwise SQL Server will not check the data & not trust the data

  1. Import in the following order

    1. Customers
    2. Products
    3. Orders
    4. OrderLines

Foreign Keys in one table are Primary Keys in another table. Example: trying to insert OrderLines without Orders (order number), Products (Product Number) won't work.

You can also follow @Nick Kavadias idea, but that could cause voilation of business rules (although it can be caught when you try to re-enable the Constraints) having orphan records.

  • Well. I can not find a way to change the order. Oct 21, 2009 at 16:43
  • 1
    just re-arrange your queries in the SSIS task.
    – Saif Khan
    Oct 21, 2009 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.