Exporting Data

Exporting Data

gsqlcmd supports exporting database data to plain text, CSV, XML, JSON, and HTML.

gsqlcmd detects the target output format by extensions.

You may try the following commands:

gsqlcmd exec master "select name from sys.databases" databases.txt
gsqlcmd exec master "select name from sys.databases" databases.csv
gsqlcmd exec master "select name from sys.databases" databases.xml
gsqlcmd exec master "select name from sys.databases" databases.json
gsqlcmd exec master "select name from sys.databases" databases.htm

You may use the /asText, /asCsv, /asHtml, /asXml and /asJson options to specify the output format explicitly.

For example:

gsqlcmd exec master "select name from sys.databases" /astext > databases.txt
gsqlcmd exec master "select name from sys.databases" /ascsv  > databases.csv
gsqlcmd exec master "select name from sys.databases" /asxml  > databases.xml
gsqlcmd exec master "select name from sys.databases" /asjson > databases.json
gsqlcmd exec master "select name from sys.databases" /ashtm  > databases.htm

gsqlcmd includes a lot of options to customize the output. See details in the Configuring Output topic.

You may place exporting SQL scripts in separate files and use a mask for output files like

gsqlcmd exec db *.sql *.htm
This website is using cookies. By continuing to browse, you give us your consent to our use of cookies as explained in our Cookie Policy.