SQL脚本的SQL Server命令行工具(3)

# generate DDL scripts for objects that do not contain 'Sale' in their name to stdout mssql-scripter -S localhost -d AdventureWorks -U sa --exclude-objects Sale

Target server version

# specify the version of SQL Server the script will be run against mssql-scripter -S -U myUser -d AdventureWorks –target-server-version “SQL Azure DB” > myData.sql

Target server edition

# specify the edition of SQL Server the script will be run against mssql-scripter -S -U myUser -d devDB –target-server-edition “SQL Server Enterprise Edition” > myData.sql

Pipe a generated script to sed

下面这个是Linux和macOS的用法。

# change a schema name in the generated DDL script # 1) generate DDL scripts for all objects in the Adventureworks database # 2) pipe generated script to sed and change all occurrences of SalesLT to SalesLT_test and save the script to a file mssql-scripter scripter -S localhost -d Adventureworks -U sa | sed -e "s/SalesLT./SalesLT_test./g" > adventureworks_SalesLT_test.sql

Script data to a file

# script all the data to a file. mssql-scripter -S localhost -d AdventureWorks -U sa --data-only > ./adventureworks-data.sql

更详细的Usage Guide或更新请参考:https://github.com/Microsoft/sql-xplat-cli/blob/dev/doc/usage_guide.md

下面执行一个命令看看效果,生成SharePoint Translation Service DatabaseCREATE语句:

mssql-scripter --server 10.2.53.22\ZEUS --database 'TranslationService_cd4699102b0745ba81ca0cf72d9ffe6e' --user sa --password '1qaz2wsxE' --file E:\CreateTranslationServiceDatabase.sql

执行结果的文件可以在这里下载。

完整PDF文档可以到Linux公社资源站下载:

------------------------------------------分割线------------------------------------------

免费下载地址在

用户名与密码都是

具体下载目录在 /2017年资料/6月/16日/MSSQL-Scripter,一个新的生成T-SQL脚本的SQL Server命令行工具/

下载方法见

------------------------------------------分割线------------------------------------------

另外还可以把连接字符串设置成环境变量:

# set environment variable MSSQL_SCRIPTER_CONNECTION_STRING with a connection string. export MSSQL_SCRIPTER_CONNECTION_STRING='Server=myserver;Database=mydb;User Id=myuser;Password=mypassword;' mssql-scripter # set environment variable MSSQL_SCRIPTER_PASSWORD so no password input is required. export MSSQL_SCRIPTER_PASSWORD='ABC123' mssql-scripter -S localhost -d AdventureWorks -U sa

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/92fb261442e6ea0044d16bd18735a734.html