views:

1191

answers:

3

I'd like to automatically generate database scripts on a regular basis. Is this possible.

+4  A: 

To generate script for an object you have to pass up to six parameters:

exec proc_genscript 
    @ServerName = 'Server Name', 
    @DBName = 'Database Name', 
    @ObjectName = 'Object Name to generate script for', 
    @ObjectType = 'Object Type', 
    @TableName = 'Parent table name for index and trigger',
    @ScriptFile = 'File name to save the script'

http://www.databasejournal.com/features/mssql/article.php/2205291

Orion Adrian
A: 

You might want to look at the SQL Server Management Objects (SMO). There are objects for scripting that will assist in generating T-SQL scripts from database objects. A good reference for this is "Programming SQL Server 2005" by Bill Hamilton. Chapter 12 in particular references the SMO utility classes.

DaveCrawford
A: 

You can use the Database Publishing Wizard, from CodePlex. It has a command-line interface.

santiiiii