SQL Server - How to "Generate and Publish Scripts" Automatically

I want to automatically (ideally from the command line in a batch file) automate the generation of the SQL Server 2008 R2 database schema.

In SSMS, I can right-click the database, select Tasks, Generate Scripts, and then follow the wizard to create a script scheme. Is there a command line version of this process that I can use?

+4
source share
2 answers

From this answer comes tools called SMOScript and ScriptDB that can do this.

If you find a way without third-party tools, share :)

+2
source

Microsoft released a new tool a few weeks ago called mssql-scripter, which is a command-line version of the SSMS Scripting Wizard. This is a Python-based open source command line tool, and you can find the official announcement here . Essentially, the script allows you to generate a T-SQL script for your database object / database as a .sql file. You can generate the file and then execute it. This may be a good solution to create your db's schema (schema is the default option). Here's a quick use example to get you started:

$ pip install mssql-scripter # script the database schema and data piped to a file. $ mssql-scripter -S localhost -d AdventureWorks -U sa > ./adventureworks.sql 

Additional usage examples are provided on our GitHub page here: https://github.com/Microsoft/sql-xplat-cli/blob/dev/doc/usage_guide.md

0
source

Source: https://habr.com/ru/post/1340654/


All Articles