Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I need to script a database schema out to T-SQL for inclusion source control. The Express version of SSMS doesn't seem to let you script the entire database, just individual tables. Are there any free tools (scripts or otherwise) that can do this ?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

This SQL script is a SQL Server 2005 table scripting tool that I wrote to reverse engineer a database schema to SQL. It might do what you want. Load it in SSMS and set 'Results to Text' from the menu. Then run the script. It will reverse engineer most of the major database objects.

share|improve this answer

Not sure if this will work in Express or not, but you could look into SQL Powershell scripting... Check this link out. It's a rough transcript of a SQL Powershell video (the link to that on the page is broken, unfortunately). Specifically, you're looking for the command that looks like this:

gci | % {$_.script()}

gci is Get-ChildItem, | just pipes that output to the next command, % is a short hand for foreach, $_ holds the current item, and we're calling the .script() function.

You should be able to save or copy that info out into a file.

For data scripting, I recommend the SSMS Tools Pack.

share|improve this answer
1  
Thanks, I already had the SSMS Tools Pack installed and while it will create CRUD scripts it won't just dump the entire schema to T-SQL. –  Alan B Dec 16 '11 at 15:55

You can do this with the SMO framework and something like Powershell.

There are a number of tutorials available online.

In brief, you will want to create an SMO UrnCollection for all objects in the DB, then pass that UrnCollection to the SMO.Scripter class to script out all the objects.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.