如何自动化“生成脚本"?SQL Server Management Studio 2008 中的任务? [英] How can I automate the "generate scripts" task in SQL Server Management Studio 2008?

查看:46
本文介绍了如何自动化“生成脚本"?SQL Server Management Studio 2008 中的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 SQL Server Management Studio 2008 中自动生成脚本.

I'd like to automate the script generation in SQL Server Management Studio 2008.

现在我要做的是:

  • 右键单击我的数据库,任务,生成脚本..."
  • 手动选择我需要的所有导出选项,然后在选择对象"选项卡上点击全选
  • 选择导出文件夹
  • 最终点击完成"按钮

有没有办法让这个任务自动化?

Is there a way to automate this task?

我想生成创建脚本,而不是更改脚本.

Edit : I want to generate creation scripts, not change scripts.

推荐答案

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.

这篇关于如何自动化“生成脚本"?SQL Server Management Studio 2008 中的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆