Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Script objects to different filenames

Author  Topic 

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-10 : 12:16:11
I'm using SQL2005 and need to script a bunch of Tables (and possibly other objects) to files. I can't make one big file with all the objects in it. I need to create an indiviual file for each object and each filename needs to be something like dbo.objectname.sql. I will be checking each file (object script) into VSS. Can someone tell me how to do this withouth having to manually generate a script for each object? Is there a way to check each object you want scripted and the SSMS spit out a file per object?

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-10 : 12:18:38
Have a look at
http://www.nigelrivett.net/DMO/DMOScriptAllDatabases.html
and this will save them to sourcessafe
http://www.nigelrivett.net/DMO/AddToSourceSafe.html

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-10 : 12:22:23
I will look at your links but I think I just found it. There is a "File per Object" option to check.
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-10 : 13:13:16
Got it to work with the "File per Object" option but I also told it to script the "USE DB" syntax and it only puts the USE DB in the first file and the rest have no USE DB at the top. Also, I noticed the Drop command no longer does an IF EXIST...DROP.
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-10 : 16:22:09
Anybody know how to make the DROP statements do an IF Exist...DROP?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-10 : 16:24:50
SSMS sucks when it comes to generating the scripts. EM did it so much better. As a result of this, a lot of us are using custom tools.

Here's graz's tool:
http://weblogs.sqlteam.com/billg/archive/2005/11/22/8414.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-10 : 17:32:57
I checked out that link. I seem to remember when Graz wrote that. I was working with him back then and remember him mentioning it but we were on SQL2000. I think that MS might have added this feature to SSMS because I just found that there is the option to scritp the DROP statement but there's also the option to script the IF NOT EXISTS (confusing because I would have expected it to say IF EXISTS) and that does script the IF EXIST...DROP. The whole generate scripts wizard is slow though.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-11 : 06:13:56
The one I posted scripts the conditional drop.
It's easy to write a dos command to add a use statement to the beginning of every file or you can add it to the code.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -