Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top