Could someone advise me on the best way to drop and recreate all objects in a database except tables (considering I must drop and create them in the correct order of dependency). More specifically, I would like to drop and recreate:
Indexes
Defaults
FK Constraints
Views
Procs
UDF
Check Constraints
Must I loop through every object in the database or is there any way to do this en masse?
Thanks.
I am currently working on creating a SSIS package that achieves this. I am using a ForEach Loop container (which contains a script task and Execute SQL task) for my tables, view, stored procedures and functions. The loop container uses a ForEach SMO enumerator. In my case I wanted to transfer objects from a different database so I added a Transfer SQL objects task to transfer objects. So far this is working pretty well.
I am having one issue though and that is with dropping my defaults. I haven't figured out how to get my SMO enumerator to pick up my defaults. If anyone can shed some light on how to configure this option I would appreciate it.
Thanks.
|||Take a look at the Transfer object that allows you to create compound scripts in dependency order.
A little more elaborate, but you can also use the Scripter.
See also http://blogs.msdn.com/mwories/archive/2005/05/07/basic-scripting.aspx for a primer on scripting.
|||Does anyone have any samples that show looping through every table in the database, then for each table dropping any foreign key constraints and indexes, then dropping the table itself?
Thanks.
No comments:
Post a Comment