Reputation: 15043
I have FK and PK all over my db and table data needs to be specified in a certain order or else I get FK/PK insertion errors. I'm tired of executing the wizard again and again to transfer data one table at a time.
In the SQL Server export data wizard there is an option to "Write a query to specify the data to transfer". I'd like to write the query myself and specify the correct order.
Will this solve my problem?
How do I do this? Can you provide a sample query (or link to one)
Upvotes: 0
Views: 1990
Reputation: 206
You can use 3rd party tools to transfer a data; these tools disable/enable constraints automatically.
Upvotes: 0
Reputation: 37205
Disable foreign keys before importing, enable them after the import:
ALTER TABLE tablename NOCHECK CONSTRAINT ALL
ALTER TABLE tablename WITH CHECK CHECK CONSTRAINT ALL
Update: Thanks for the comments, I fixed the syntax.
Upvotes: 1
Reputation: 89661
You could always save the package and then open and edit the package to put things in the right order (you might have to copy the data flow several times and put dependencies between them)
Upvotes: 1