Subject: Scripting database objects in dependency order
Posted By: cmccloskey56 Post Date: 3/15/2006 2:08:20 PM
We're building a new application on SQL 2005, requiring a new database and objects. I'm making frequent changes to the objects, often making a specific change to all of the tables. In SQL 2000 I would just script out the database, make my change, and apply the script (assuming that the tables are empty or can be easily refilled).
When I script out the objects in SQL 2005 I get an option to generate create or drop statements, but not both (if exists... drop table). More importantly, the objects aren't scripted in dependency order (i.e. the customer table must be created first but deleted last).

Am I missing something? Is there an option on the scripting wizard to give me the functionality like it was in SQL 2000? Is there anything else I can try, besides writing my own scripting app?

Thanks for listening!

Colleen



Reply By: sqlhead Reply Date: 3/15/2006 9:20:56 PM
So there are two issues here...

1. How to generate if exists drop...create?
A. I am not sure how offhand just via Mgmt Studio to accomplish this exact requriement. What I can tell you is that using the Script Wizard (right-click on DB, Tasks, Generate Scripts), you get several options under the General Tab on the "Choose Scripting Options" step including "include if not exists". What this does is if not exists then create so its not exactly what you want aka a straight drop then create but its as close as I can find offhand just via the UIs.

2. How to script dependent DB objects in order?
A. While I am not aware of anyway to specify ordering, you can use the same Script Wizard I mentioned above with another General Script option/setting for dependant DB objects.

Hope this helps,
Derek
"sqlhead"

Go to topic 41483

Return to index page 342
Return to index page 341
Return to index page 340
Return to index page 339
Return to index page 338
Return to index page 337
Return to index page 336
Return to index page 335
Return to index page 334
Return to index page 333