September 2, 2010 at 10:30 am
I was given a task to insert/select tables from another database. All destination tables are empty now. Most of the tables have foreign keys. How can I disable all of them ? As well as how to re-enable again ?
Thanks
September 2, 2010 at 10:39 am
Why disable the foreign keys? Just load the data into the tables in the correct order.
The following script will show you the correct order to load the data.
Find Table Reference Levels:
September 2, 2010 at 10:50 am
I agree with Michael.
Load the data in the correct order, or delete in the correct order.
Here is an alternative script to help with figuring out the order:
http://jasonbrimhall.info/2010/02/01/key-discovery-iii/
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 2, 2010 at 11:15 am
Hmmm...
There are 38 tables, they are all from same schema. I created a cursor to script insert /select against source database. Putting them in correct order would be rather difficult. I will probably try to shuffle generated script batches in that order .
September 2, 2010 at 11:26 am
SQL Guy-482125 (9/2/2010)
Hmmm...There are 38 tables, they are all from same schema. I created a cursor to script insert /select against source database. Putting them in correct order would be rather difficult. I will probably try to shuffle generated script batches in that order .
I understand where you are coming from. That is the reason people have come up with these kinds of scripts. I have a chain of 50+ tables related to some data.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 2, 2010 at 11:46 am
I probably found even better solution. Sinse these tables initially clean in destination, I created 2 scripts in SSMS: tables and F.K., then I dropped all tables, ran script that creates anly tables, then I ran my script for insert/select generated from cursor against the source, and finally ran F.K. script.
September 2, 2010 at 11:50 am
Ok. What if you need to do this after it rolls to production?
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 2, 2010 at 12:02 pm
CirquedeSQLeil (9/2/2010)
Ok. What if you need to do this after it rolls to production?
Just drop the tables, add them, add the data, add the FKs. 😛 😉 :w00t:
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 2, 2010 at 12:12 pm
WayneS (9/2/2010)
CirquedeSQLeil (9/2/2010)
Ok. What if you need to do this after it rolls to production?Just drop the tables, add them, add the data, add the FKs. 😛 😉 :w00t:
That reminds me...I have a report for work that needs me to do that very thing 😉
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 2, 2010 at 1:45 pm
That's a good question. Actually that exercise was like a "rehearsal" before deployment to production. There were too many errors, so we ran same things until install became clean.
Once installed on production, all the values will be entered through GUI, of course.
September 2, 2010 at 2:45 pm
SQL Guy-482125 (9/2/2010)
That's a good question. Actually that exercise was like a "rehearsal" before deployment to production. There were too many errors, so we ran same things until install became clean.Once installed on production, all the values will be entered through GUI, of course.
K - that's good.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply