views:

38

answers:

3

hi,

i want to extract specific database tables & stored procedures into one master script. Do you know any software that can help me do this faster? I've tried using the SQL Database publishing tool, but it's not that efficient since its gathering tables that I didn't select.

+2  A: 

In SQL Server 2005, right click on the database, then select Tasks, and then select Generate Scripts.

Generating SQL Scripts in SQL Server 2005

As mentioned in that link, I'm fairly sure you have to generate the DROP and CREATE statements separately.

Mitch Wheat
hi Mitch, thanks. But I already know how to do this, i'm looking for an automated way to produce the statements in one document/master script.
Martin Ongtangco
A: 

I use Redgate SQL compare for this (by comparing to an empty DB), as well as for doing upgrades between all my DB versions (I save a copy of the DB for each released version, and then just do a compare between current and previous to get a change script for that version).

I have found the "Generate Scripts" does a bad job in some cases with dependencies - eg, it will try to create a stored procedure that uses a table before the table is created, causing the script to fail. I'll accept I'm possibly using it wrong, but SQL Compare "just works". The scripts it generates are also enclosed in a transaction -- so if something fails, the whole change is rolled back. You don't end up with a half-populated or half-upgraded database.

Downside is that this is a commercial tool, but IMHO worth the money.

gregmac
Worth every penny, Red-Gate just makes good tools that work.
HLGEM
A: 

Try DBSourceTools. http://dbsourcetools.codeplex.com
Its open source, and specifically designed to script databases - tables, views, procs to disk.
It also allows you to select which tables, views, db-objects to script.

blorkfish