Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 3e9097b

Browse files
author
Tara Raj
authored
Updated documentation page with usage_guide
1 parent a5ea170 commit 3e9097b

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

doc/documentation_page.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
1-
#Get Started with mssql-scripter
1+
# Get Started with mssql-scripter
2+
3+
mssql-scripter is the multiplatform command line equivalent of the widely used Generate Scripts Wizard experience in SSMS.
4+
5+
You can use mssql-scripter on Linux, macOS, and Windows to generate data definition language (DDL) and data manipulation language (DML) T-SQL scripts for database objects in SQL Server running anywhere, Azure SQL Database, and Azure SQL Data Warehouse. You can save the generated T-SQL script to a .sql file or pipe it to standard *nix utilities (for example, sed, awk, grep) for further transformations. You can edit the generated script or check it into source control and subsequently execute the script in your existing SQL database deployment processes and DevOps pipelines with standard multiplatform SQL command line tools such as sqlcmd.
6+
7+
## Install
8+
9+
For information about installation, please see the LINK/install guide/LINK.
10+
11+
## Dump database object schema
12+
13+
# generate DDL scripts for all objects in the Adventureworks database and save the script to a file
14+
mssql-scripter -S localhost -d AdventureWorks -U sa
15+
16+
# alternatively, specify the schema only flag to generate DDL scripts for all objects in the Adventureworks database and save the script to a file
17+
mssql-scripter -S localhost -d AdventureWorks -U sa -f ./adventureworks.sql
18+
19+
## Dump database object data
20+
21+
# generate DDL scripts for all objects in the Adventureworks database and save the script to stdout.
22+
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only
23+
24+
## Dump the database object schema and data
25+
26+
# script the database schema and data piped to a file.
27+
mssql-scripter -S localhost -d AdventureWorks -U sa --schema-and-data > ./adventureworks.sql
28+
29+
# execute the generated above script with sqlcmd
30+
sqlcmd -S mytestserver -U sa -i ./adventureworks.sql
31+
32+
## Include database objects
33+
34+
# generate DDL scripts for objects that contain 'Employee' in their name to stdout
35+
mssql-scripter -S localhost -d AdventureWorks -U sa --include-objects Employee
36+
37+
# generate DDL scripts for the dbo schema and pipe the output to a file
38+
mssql-scripter -S localhost -d AdventureWorks -U sa --include-objects dbo. > ./dboschema.sql
39+
40+
## Exclude database objects
41+
42+
# generate DDL scripts for objects that do not contain 'Sale' in their name to stdout
43+
mssql-scripter -S localhost -d AdventureWorks -U sa --exclude-objects Sale
44+
45+
## Target server version
46+
47+
# specify the version of SQL Server the script will be run against
48+
mssql-scripter -S myServer -d AdventureWorks -U myUser –-target-server-version "AzureDB" > myData.sql
49+
50+
## Target server edition
51+
52+
# specify the edition of SQL Server the script will be run against
53+
mssql-scripter -S localhost -d AdventureWorks -U myUser –-target-server-edition "Enterprise" > myData.sql
54+
55+
## Pipe a generated script to sed
56+
Note this example is for Linux and macOS usage.
57+
58+
# change a schema name in the generated DDL script
59+
# 1) generate DDL scripts for all objects in the Adventureworks database
60+
# 2) pipe generated script to sed and change all occurrences of SalesLT to SalesLT_test and save the script to a file
61+
$ mssql-scripter -S localhost -d Adventureworks -U sa | sed -e "s/SalesLT./SalesLT_test./g" > adventureworks_SalesLT_test.sql
62+
63+
## Script data to a file
64+
65+
# script all the data to a file.
66+
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only > ./adventureworks-data.sql
67+
68+
## Set environment variables
69+
You can set environment variables for your connection string through the following steps:
70+
71+
72+
# set environment variable MSSQL_SCRIPTER_CONNECTION_STRING with a connection string.
73+
$ export MSSQL_SCRIPTER_CONNECTION_STRING='Server=myserver;Database=mydb;User Id=myuser;Password=mypassword;'
74+
$ mssql-scripter
75+
76+
# set environment variable MSSQL_SCRIPTER_PASSWORD so no password input is required.
77+
$ export MSSQL_SCRIPTER_PASSWORD='ABC123'
78+
$ mssql-scripter -S localhost -d AdventureWorks -U sa

0 commit comments

Comments
 (0)