Exporting Data with gsqlcmd
gsqlcmd supports exporting data from databases to plain text, CSV, XML, JSON, and HTML.
gsqlcmd detects the target output format by extensions.
You can 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 can 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 can place exporting SQL scripts in separate files and use a mask for output files like
gsqlcmd exec db *.sql *.htm