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

Commit 1fbbd9c

Browse files
author
Tara Raj
authored
Updated with sqlcmd usage
1 parent 697e83f commit 1fbbd9c

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

doc/documentation_page.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,71 +10,83 @@ For information about installation, please see the LINK/install guide/LINK.
1010

1111
The examples in this guide use the Adventureworks sample database. You can download the sample [here](https://www.microsoft.com/en-us/download/details.aspx?id=49502).
1212

13-
## Dump database object schema
13+
## Generate scripts
14+
Use mssql-scripter to generate scripts for database schema and/or data by including specific objects, targeting server versions/editions, and piping the script to files.
15+
16+
### Dump database object schema
1417

1518
# generate DDL scripts for all objects in the Adventureworks database and save the script to a file
1619
mssql-scripter -S localhost -d AdventureWorks -U sa
1720

1821
# alternatively, specify the schema only flag to generate DDL scripts for all objects in the Adventureworks database and save the script to a file
1922
mssql-scripter -S localhost -d AdventureWorks -U sa -f ./adventureworks.sql
2023

21-
## Dump database object data
24+
### Dump database object data
2225

2326
# generate DDL scripts for all objects in the Adventureworks database and save the script to stdout.
2427
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only
2528

26-
## Dump the database object schema and data
29+
### Dump the database object schema and data
2730

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

3134
# execute the generated above script with sqlcmd
3235
sqlcmd -S mytestserver -U sa -i ./adventureworks.sql
3336

34-
## Include database objects
37+
### Include database objects
3538

3639
# generate DDL scripts for objects that contain 'Employee' in their name to stdout
3740
mssql-scripter -S localhost -d AdventureWorks -U sa --include-objects Employee
3841

3942
# generate DDL scripts for the dbo schema and pipe the output to a file
4043
mssql-scripter -S localhost -d AdventureWorks -U sa --include-objects dbo. > ./dboschema.sql
4144

42-
## Exclude database objects
45+
### Exclude database objects
4346

4447
# generate DDL scripts for objects that do not contain 'Sale' in their name to stdout
4548
mssql-scripter -S localhost -d AdventureWorks -U sa --exclude-objects Sale
4649

47-
## Target server version
50+
### Target server version
4851

4952
# specify the version of SQL Server the script will be run against
5053
mssql-scripter -S myServer -d AdventureWorks -U myUser –-target-server-version "AzureDB" > myData.sql
5154

52-
## Target server edition
55+
### Target server edition
5356

5457
# specify the edition of SQL Server the script will be run against
5558
mssql-scripter -S localhost -d AdventureWorks -U myUser –-target-server-edition "Enterprise" > myData.sql
5659

57-
## Pipe a generated script to sed
60+
### Pipe a generated script to sed
5861
Note this example is for Linux and macOS usage.
5962

6063
# change a schema name in the generated DDL script
6164
# 1) generate DDL scripts for all objects in the Adventureworks database
6265
# 2) pipe generated script to sed and change all occurrences of SalesLT to SalesLT_test and save the script to a file
63-
$ mssql-scripter -S localhost -d Adventureworks -U sa | sed -e "s/SalesLT./SalesLT_test./g" > adventureworks_SalesLT_test.sql
66+
mssql-scripter -S localhost -d Adventureworks -U sa | sed -e "s/SalesLT./SalesLT_test./g" > adventureworks_SalesLT_test.sql
6467

65-
## Script data to a file
68+
### Script data to a file
6669

6770
# script all the data to a file.
6871
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only > ./adventureworks-data.sql
6972

70-
## Set environment variables
73+
### Set environment variables
7174
You can set environment variables for your connection string through the following steps:
7275

7376

7477
# set environment variable MSSQL_SCRIPTER_CONNECTION_STRING with a connection string.
75-
$ export MSSQL_SCRIPTER_CONNECTION_STRING='Server=myserver;Database=mydb;User Id=myuser;Password=mypassword;'
76-
$ mssql-scripter
78+
export MSSQL_SCRIPTER_CONNECTION_STRING='Server=myserver;Database=mydb;User Id=myuser;Password=mypassword;'
79+
mssql-scripter
7780

7881
# set environment variable MSSQL_SCRIPTER_PASSWORD so no password input is required.
79-
$ export MSSQL_SCRIPTER_PASSWORD='ABC123'
80-
$ mssql-scripter -S localhost -d AdventureWorks -U sa
82+
export MSSQL_SCRIPTER_PASSWORD='ABC123'
83+
mssql-scripter -S localhost -d AdventureWorks -U sa
84+
85+
## Run your scripts using sqlcmd
86+
Now that you have generated a script for your database objects, you can execute the script using sqlcmd such as in the example below.
87+
88+
# script all the data to a file.
89+
mssql-scripter -S localhost -d AdventureWorks -U sa --data-only > ./adventureworks-data.sql
90+
sqlcmd -S localhost -d AdventureWorks -U sa -i`./adventureworks-data.sql
91+
92+
You can find more details on using sqlcmd [here](https://docs.microsoft.com/en-us/sql/relational-databases/scripting/sqlcmd-use-the-utility).

0 commit comments

Comments
 (0)