MSSQL-Scripter,一个新的生成T-SQL脚本的SQL Server命令行工具
這里向大家介紹一個(gè)新的生成T-SQL腳本的SQL Server命令行工具:mssql-scripter。它支持在SQL Server、Azure SQL DB以及Azure SQL DW中為數(shù)據(jù)庫(kù)生成CREATE和INSERT T-SQL腳本。
Mssql-scripter是一個(gè)跨平臺(tái)的命令行工具,功能等同于SQL Server Management Studio中的Generate and Publish Scripts Wizard。
咱們能夠在Linux、macOS和Windows上使用它生成數(shù)據(jù)定義語(yǔ)言(DDL-Data Definition Language)和數(shù)據(jù)操縱語(yǔ)言(DML – Data Manipulation Language),并且生成的T-SQL腳本可以運(yùn)行在所有平臺(tái)的SQL Server、Azure SQL Database、以及Azure SQL Data Warehouse中。
?
Installation
1.?? Windows
a)?????? 安裝Python,最新安裝包下載地址:https://www.python.org/downloads/,注意安裝的時(shí)候要選擇”Add Python to PATH”選項(xiàng):
b)????? 安裝mssql-scripter,命令行里執(zhí)行下面命令:
pip install mssql-scripter2.?? Linux
a)????? 檢查pip版本,是否是9.0及其以上:
pip –versionb)????? 如果pip未安裝或者版本低于9.0,使用如下命令安裝以及升級(jí)版本:
sudo apt-get install python-pipsudo pip install --upgrade pipc)????? 安裝mssql-scripter:
sudo pip install mssql-scripter如果系統(tǒng)是Ubuntu或者Debian,需要安裝libunwind8軟件包:
Ubuntu 14 & 17
執(zhí)行如下命令:
sudo apt-get updatesudo apt-get install libunwind8Debian 8(暫時(shí)沒(méi)有環(huán)境,未測(cè)試)
文件‘/etc/apt/sources.list’需要更新:
deb http://ftp.us.debian.org/debian/ jessie main執(zhí)行如下命令:
sudo apt-get updatesudo apt-get install libunwind83.?? macOS(暫時(shí)沒(méi)有環(huán)境,未測(cè)試)
a)?????? 檢查pip版本,是否是9.0及其以上:
pip –versionb)????? 如果pip未安裝或者版本低于9.0,使用如下命令安裝以及升級(jí)版本:
sudo apt-get install python-pipsudo pip install --upgrade pipc)?????? 安裝mssql-scripter:
sudo pip install mssql-scripter?
Usage Guide
幫助命令:
mssql-scripter -h
usage: mssql-scripter [-h] [--connection-string ?| -S ] [-d] [-U] [-P] [-f]
? ? ? ? ? ? ? ? ? [--data-only | --schema-and-data]
? ? ? ? ? ? ? ? ? [--script-create | --script-drop | --script-drop-create]
? ? ? ? ? ? ? ? ? [--target-server-version {2005,2008,2008R2,2012,2014,2016,vNext,AzureDB,AzureDW}]
? ? ? ? ? ? ? ? ? [--target-server-edition {Standard,PersonalExpress,Enterprise,Stretch}]
? ? ? ? ? ? ? ? ? [--include-objects [[...]]] [--exclude-objects [[...]]]
? ? ? ? ? ? ? ? ? [--ansi-padding] [--append] [--check-for-existence] [-r]
? ? ? ? ? ? ? ? ? [--convert-uddts] [--include-dependencies] [--headers]
? ? ? ? ? ? ? ? ? [--constraint-names] [--unsupported-statements]
? ? ? ? ? ? ? ? ? [--object-schema] [--bindings] [--collation]
? ? ? ? ? ? ? ? ? [--defaults] [--extended-properties] [--logins]
? ? ? ? ? ? ? ? ? [--object-permissions] [--owner] [--use-database]
? ? ? ? ? ? ? ? ? [--statistics] [--change-tracking] [--check-constraints]
? ? ? ? ? ? ? ? ? [--data-compressions] [--foreign-keys]
? ? ? ? ? ? ? ? ? [--full-text-indexes] [--indexes] [--primary-keys]
? ? ? ? ? ? ? ? ? [--triggers] [--unique-keys] [--display-progress]
? ? ? ? ? ? ? ? ? [--enable-toolsservice-logging] [--version]
Microsoft SQL Server Scripter Command Line Tool. Version 1.0.0a1
optional arguments:
? -h, --help ? ? ? ? ? ?show this help message and exit
? --connection-string ? Connection string of database to script. If connection
? ? ? ? ? ? ? ? ? ? ? ? string and server are not supplied, defaults to value
? ? ? ? ? ? ? ? ? ? ? ? in Environment Variable
? ? ? ? ? ? ? ? ? ? ? ? MSSQL_SCRIPTER_CONNECTION_STRING.
? -S , --server ? ? ? ? Server name.
? -d , --database ? ? ? Database name.
? -U , --user ? ? ? ? ? Login ID for server.
? -P , --password ? ? ? Password.
? -f , --file ? ? ? ? ? Output file name.
? --data-only ? ? ? ? ? Generate scripts that contains data only.
? --schema-and-data ? ? Generate scripts that contain schema and data.
? --script-create ? ? ? Script object CREATE statements.
? --script-drop ? ? ? ? Script object DROP statements
? --script-drop-create ?Script object CREATE and DROP statements.
? --target-server-version {2005,2008,2008R2,2012,2014,2016,vNext,AzureDB,AzureDW}
? ? ? ? ? ? ? ? ? ? ? ? Script only features compatible with the specified SQL
? ? ? ? ? ? ? ? ? ? ? ? Version.
? --target-server-edition {Standard,PersonalExpress,Enterprise,Stretch}
? ? ? ? ? ? ? ? ? ? ? ? Script only features compatible with the specified SQL
? ? ? ? ? ? ? ? ? ? ? ? Server database edition.
? --include-objects [ [ ...]]
? ? ? ? ? ? ? ? ? ? ? ? Database objects to include in script.
? --exclude-objects [ [ ...]]
? ? ? ? ? ? ? ? ? ? ? ? Database objects to exclude from script.
? --ansi-padding ? ? ? ?Generates ANSI Padding statements.
? --append ? ? ? ? ? ? ?Append script to file.
? --check-for-existence
? ? ? ? ? ? ? ? ? ? ? ? Check for database object existence.
? -r, --continue-on-error
? ? ? ? ? ? ? ? ? ? ? ? Continue scripting on error.
? --convert-uddts ? ? ? Convert user-defined data types to base types.
? --include-dependencies
? ? ? ? ? ? ? ? ? ? ? ? Generate script for the dependent objects for each
? ? ? ? ? ? ? ? ? ? ? ? object scripted.
? --headers ? ? ? ? ? ? Include descriptive headers for each object scripted.
? --constraint-names ? ?Include system constraint names to enforce declarative
? ? ? ? ? ? ? ? ? ? ? ? referential integrity.
? --unsupported-statements
? ? ? ? ? ? ? ? ? ? ? ? Include statements in the script that are not
? ? ? ? ? ? ? ? ? ? ? ? supported on the target SQL Server Version.
? --object-schema ? ? ? Prefix object names with the object schema.
? --bindings ? ? ? ? ? ?Script options to set binding options.
? --collation ? ? ? ? ? Script the objects that use collation.
? --defaults ? ? ? ? ? ?Script the default values.
? --extended-properties
? ? ? ? ? ? ? ? ? ? ? ? Script the extended properties for each object
? ? ? ? ? ? ? ? ? ? ? ? scripted.
? --logins ? ? ? ? ? ? ?Script all logins available on the server, passwords
? ? ? ? ? ? ? ? ? ? ? ? will not be scripted.
? --object-permissions ?Generate object-level permissions.
? --owner ? ? ? ? ? ? ? Script owner for the objects.
? --use-database ? ? ? ?Generate USE DATABASE statement.
? --statistics ? ? ? ? ?Script all statistics.
? --change-tracking ? ? Script the change tracking information.
? --check-constraints ? Script the check constraints for each table or view
? ? ? ? ? ? ? ? ? ? ? ? scripted.
? --data-compressions ? Script the data compression information.
? --foreign-keys ? ? ? ?Script the foreign keys for each table scripted.
? --full-text-indexes ? Script the full-text indexes for each table or indexed
? ? ? ? ? ? ? ? ? ? ? ? view scripted.
? --indexes ? ? ? ? ? ? Script the indexes (XML and clustered) for each table
? ? ? ? ? ? ? ? ? ? ? ? or indexed view scripted.
? --primary-keys ? ? ? ?Script the primary keys for each table or view
? ? ? ? ? ? ? ? ? ? ? ? scripted.
? --triggers ? ? ? ? ? ?Script the triggers for each table or view scripted.
? --unique-keys ? ? ? ? Script the unique keys for each table or view
? ? ? ? ? ? ? ? ? ? ? ? scripted.
? --display-progress ? ?Display scripting progress.
? --enable-toolsservice-logging
? ? ? ? ? ? ? ? ? ? ? ? Enable verbose logging.
? --version ? ? ? ? ? ? show program's version number and exit
相關(guān)例子:
下面這個(gè)是Linux和macOS的用法。
Script data to a file
更詳細(xì)的Usage Guide或更新請(qǐng)參考:https://github.com/Microsoft/sql-xplat-cli/blob/dev/doc/usage_guide.md。
?
下面執(zhí)行一個(gè)命令看看效果,生成SharePoint Translation Service Database的CREATE語(yǔ)句:
執(zhí)行結(jié)果的文件可以在這里下載:http://files.cnblogs.com/files/lavender000/CreateTranslationServiceDatabase.zip。
另外還可以把連接字符串設(shè)置成環(huán)境變量:
# 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
原文地址:http://www.cnblogs.com/lavender000/p/6886560.html
.NET社區(qū)新聞,深度好文,微信中搜索dotNET跨平臺(tái)或掃描二維碼關(guān)注
總結(jié)
以上是生活随笔為你收集整理的MSSQL-Scripter,一个新的生成T-SQL脚本的SQL Server命令行工具的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 在CentOS上使用Jexus托管运行
- 下一篇: 深入理解C#:编程技巧总结(二)