且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何自动化“生成脚本"?SQL Server Management Studio 2008 中的任务?

更新时间:2021-11-11 01:05:10

Brann 在 Visual Studio 2008 SP1 团队套件中提到的是数据库发布向导的 1.4 版.它与 sql server 2008(可能只是专业版?)一起安装到 Program FilesMicrosoft SQL Server90ToolsPublishing1.4.来自服务器资源管理器的 VS 调用只是调用它.您可以通过命令行实现相同的功能,例如:

What Brann is mentioning from the Visual Studio 2008 SP1 Team Suite is version 1.4 of the Database Publishing Wizard. It's installed with sql server 2008 (maybe only professional?) to Program FilesMicrosoft SQL Server90ToolsPublishing1.4. The VS call from server explorer is simply calling this. You can achieve the same functionality via the command line like:

sqlpubwiz help script

我不知道 v1.4 是否有与 v1.1 相同的麻烦(用户转换为角色,约束没有按正确的顺序创建),但这对我来说不是解决方案,因为它没有't 脚本对象到不同的文件,就像 SSMS 中的 Tasks->Generate Scripts 选项一样.我目前正在使用 Scriptio 的修改版本(使用 MS SMO API)作为数据库发布向导 (sqlpubwiz.exe) 的改进替代品.目前无法从命令行编写脚本,我可能会在未来添加该贡献.

I don't know if v1.4 has the same troubles that v1.1 did (users are converted to roles, constraints are not created in the right order), but it is not a solution for me because it doesn't script objects to different files like the Tasks->Generate Scripts option in SSMS does. I'm currently using a modified version of Scriptio (uses the MS SMO API) to act as an improved replacement for the database publishing wizard (sqlpubwiz.exe). It's not currently scriptable from the command line, I might add that contribution in the future.

Scriptio 最初发布在 Bill Graziano 的博客上,但随后由 Bill 发布到 CodePlex 并由其他人更新.阅读讨论以了解如何编译以用于 SQL Server 2008.

Scriptio was originally posted on Bill Graziano's blog, but has subsequently been released to CodePlex by Bill and updated by others. Read the discussion to see how to compile for use with SQL Server 2008.

http://scriptio.codeplex.com/

我已经开始使用 RedGate 的 SQL 比较产品来做到这一点.它是 sql 发布向导本应具备的所有功能的非常好的替代品.您选择一个数据库、备份或快照作为源,并选择一个文件夹作为输出位置,它会将所有内容很好地转储到文件夹结构中.它恰好与他们的其他产品 SQL Source Control 使用的格式相同.

I've since started using RedGate's SQL Compare product to do this. It's a very nice replacement for all that sql publishing wizard should have been. You choose a database, backup, or snapshot as the source, and a folder as the output location and it dumps everything nicely into a folder structure. It happens to be the same format that their other product, SQL Source Control, uses.