snippetsqlMinor
How can I dump the schema of a SQL server database on Linux?
Viewed 0 times
dumpcanthesqldatabaselinuxhowserverschema
Problem
UPDATE:
My goal is to get a set of SQL commands that can b executed and would recreate the database that I made including all the resources such as tables, indexes, trigger functions, privilege grants etc - same as what the MySQL and POstgres commands below do. I'm working on an open source project and I want to be able to give a sql file to the end user so all they ned to do is run it to get their database correctly set up.
On MySQL:
On Postgres:
I can't seem to find an equivalent for SQL server on Linux, though surely such a common task must be easily done?
I have the sqlcmd utility running ok:
```
ubuntu@ubuntu:~$ sqlcmd -?
Microsoft (R) SQL Server Command Line Tool
Version 17.6.0001.1 Linux
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-g
My goal is to get a set of SQL commands that can b executed and would recreate the database that I made including all the resources such as tables, indexes, trigger functions, privilege grants etc - same as what the MySQL and POstgres commands below do. I'm working on an open source project and I want to be able to give a sql file to the end user so all they ned to do is run it to get their database correctly set up.
On MySQL:
mysqldump --no-data somedatabasename dump_schema_mysql.outOn Postgres:
pg_dump -s somedatabasename > dump_schema_postgres.outI can't seem to find an equivalent for SQL server on Linux, though surely such a common task must be easily done?
I have the sqlcmd utility running ok:
```
ubuntu@ubuntu:~$ sqlcmd -?
Microsoft (R) SQL Server Command Line Tool
Version 17.6.0001.1 Linux
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-g
Solution
Check out mssql-scripter. It's cross-platform and created by Microsoft. It has a bunch of options to control how the scripting happens.
Context
StackExchange Database Administrators Q#273158, answer score: 4
Revisions (0)
No revisions yet.