开发者

Automatic "Script database as... create" for SQL Server 2008

开发者 https://www.devze.com 2023-02-07 02:23 出处:网络
I\'d like to make a daily automatic creation of the creation script for a database in SQL Server 2008, meaning having a (bat, exe, ... whatever) that creates a text file with the very same output obta

I'd like to make a daily automatic creation of the creation script for a database in SQL Server 2008, meaning having a (bat, exe, ... whatever) that creates a text file with the very same output obtained by right-clicking on the database in SQL Management Studio and do Script database as... --> Create to... --> New Query window.

Any hint?

Thanks in advance,

Mauro

EDIT 1: We already used SMO but a couple of things are annoying

  • Needs compatibility pack in SQL Server 开发者_JAVA百科2008 (confirm?)
  • Some things were not created in script (some indexes and keys and in table creation schema is lost)

Best choice for me would something with a powershell script but any other idea is welcome!


You can use SMO. For example: http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated (see the Scripting Objects section).

More info on SMO: http://msdn.microsoft.com/en-us/library/ms162169.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消