Generate SQL server scripts from command line?

寵の児 提交于 2019-11-30 03:29:00

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 Scripter class.

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

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

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).

The download for mssql-scripter is via pip as it is Python-based: 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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!