mssql-cmd - SQL Server interactive and batch query command-line tool »

Download mssql-cmd Free Trial »

Unload SQL Server data to flat file (CSV, TSV, TXT)

parameters:

delimiter: delimiter char ("|",",","#","TAB","WHITESPACE")

quote: quote char (quote=' => single quotes, quote=" => double quotes)

recorddelimiter: record delimiter, default is CRLF

header: y|n, print field name at first line

table: table name ("all" for unload all table)

query: sql query string (can not use multi-line sql)

sqlfile: sql script file contains the query you want to unload

schema: schema name, use this prameter to unload specific schema's data, if not set, use logon user's default schema

datafile: data file name

folder: data files folder (for unload all table)

dateformat: date format (e.g. "yyyy-mm-dd hh24:mi:ss")

timestampformat: timestamp format (e.g. "yyyy-mm-dd-hh24.mi.ss.ff6")

quit = y|n (quit mssql-cmd after run in batch mode)


Unload table example mssql-cmd> unload table=jobs datafile=e:\temp\tables\jobs.txt delimiter="," header=y;
Unload query example mssql-cmd> unload query="select job_id,job_title from jobs" > datafile=e:\temp\tables\jobs_part.txt > delimiter="," > header=y;
Unload as sqlfile example sqlfile content: unload_jobs.sql select job_id,job_title from jobs mssql-cmd> unload sqlfile=e:\temp\tables\unload_jobs.sql > datafile=e:\temp\tables\jobs_part2.txt > delimiter="," quote=" > header=y;
Unload schema example mssql-cmd> unload table=all folder=e:\temp\tables delimiter="," header=y;
In batch mode mssql-cmd dsn="pan:withdata@192.168.0.102:1433/test" task=unload table=all folder=e:\temp\tables delimiter="," header=y quit=y