windows 从命令行生成 SQL 服务器脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1309822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:01:09  来源:igfitidea点击:

Generate SQL server scripts from command line?

windowssql-server-2008scriptingwizardssms

提问by Luke Sampson

In Microsoft SQL Server Management Studio 2008 there is a "Generate scripts..." option under the Tasks menu. I'm just wondering if this tool is available from the command line somehow?

在 Microsoft SQL Server Management Studio 2008 中,任务菜单下有一个“生成脚本...”选项。我只是想知道这个工具是否可以从命令行以某种方式使用?

Screenshot of Generate SQL Server Scripts Wizard

生成 SQL Server 脚本向导的屏幕截图

It looks similar to the sqlpubwiz.exe command line tool that was available for SQL Server 2005, but I can't find this executable anywhere in the SQL 2008 installation.

它看起来类似于可用于 SQL Server 2005 的 sqlpubwiz.exe 命令行工具,但我无法在 SQL 2008 安装中的任何位置找到该可执行文件。

采纳答案by Remus Rusanu

The script generating options of Management Studio are just a wrapper around the SMO scripting capabilities. Simple scripts are obtained by using the Script()method on various SMO types. More complex scripts are created by the specialized Scripterclass.

Management Studio 的脚本生成选项只是SMO 脚本功能的包装。通过Script()在各种 SMO 类型上使用该方法获得简单的脚本。更复杂的脚本由专门的Scripter类创建。

Command line tools can be easily created by using the SMO libraries.

可以使用 SMO 库轻松创建命令行工具。

回答by José Augusto Guimar?es

The SQLPubWiz.Exe for SQL2008 R2 on my PC is located on "C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Publishing\1.4"

我 PC 上 SQL2008 R2 的 SQLPubWiz.Exe 位于“C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Publishing\1.4”

回答by Tara Raj

You can use mssql-scripter, a command line tool that generates T-SQL scripts for databases and database objects (works on Windows, macOS, and Linux).

您可以使用 mssql-scripter,这是一个为数据库和数据库对象生成 T-SQL 脚本的命令行工具(适用于 Windows、macOS 和 Linux)。

The download for mssql-scripter is via pip as it is Python-based: pip install mssql-scripter

mssql-scripter 的下载是通过 pip 进行的,因为它是基于 Python 的:pip install mssql-scripter

You'll run a command similar to the following to script the database schema and data to a file: $ mssql-scripter -S localhost -d AdventureWorks -U sa --schema-and-data > ./adventureworks.sql More usage examples: https://github.com/Microsoft/sql-xplat-cli/blob/dev/doc/usage_guide.md

您将运行类似于以下内容的命令将数据库架构和数据脚本化到文件中: $ mssql-scripter -S localhost -d AdventureWorks -U sa --schema-and-data > ./adventureworks.sql 更多用法示例: https://github.com/Microsoft/sql-xplat-cli/blob/dev/doc/usage_guide.md

This project can be found at this GitHub repo - https://github.com/Microsoft/sql-xplat-cli

这个项目可以在这个 GitHub 存储库中找到 - https://github.com/Microsoft/sql-xplat-cli

回答by José Augusto Guimar?es

SQLPUBWIZ SCRIPT -d yourDBName -S yourServerName -U userName -P userPassword scriptFilewithPath

SQLPUBWIZ SCRIPT -d yourDBName -S yourServerName -U userName -P userPassword scriptFilewithPath

Download for SQL2005 http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A

下载 SQL2005 http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A