Generate SQL server scripts from command line?

帅比萌擦擦* 提交于 2019-12-18 11:25:23

问题


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?

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.


回答1:


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.




回答2:


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




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/1309822/generate-sql-server-scripts-from-command-line

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