Every time I want to create a script of the database structure (and data) of our deployment database (a brand new database with the software's basic data), I have go to SSMS, select the database, Tasks -> Scripts -> Generate Scripts. Then I have a very specific setting which I have to change every single time to the same values.
This is very time consuming and looks like a task that could very well be automated. Is it possible to automate this task from within SSMS, with my specific settings? If not, is there a way to automate it outside SSMS? I do not discard writing a C# console program to perform that, this task is not for the final user it's for our labs.
UPDATE
The objective here, as usual, is getting the solution which will take less time. So, before I got to the C# coding level, I would like to try automating the exist开发者_JAVA百科ing tools. The order would be:
- Can I automate from SSMS?
- Can I automate by running a outside script?
- How can I automate with C# coding? (the learning resources were pointed out by Nicholas Carey)
What are you using the script for? (I can think of backup, release versioning, source control for logging each change)
- backup -> could be done by keeping a database backup
- release versioning -> perhaps use SMO as suggested, you'd have control of what gets scripted and in what order
- source control -> for the time it would take to develop/test/refine, Red Gate's http://www.red-gate.com/products/sql-development/sql-source-control/ might be a better answer
Look at SMO: http://msdn.microsoft.com/en-us/library/ms162169(v=SQL.100).aspx
Then script your database, put the scripts in source control and require that changes be made via scripts.
精彩评论