sqlexport - export data from database tables into files
SYNOPSIS
sqlexport [OPTION...] [-o DESTINATION] [TABLE...]
DESCRIPTION
sqlexport retrieves data from the named TABLE(s) and writes the result to the named DESTINATION file. If more than one TABLEs are specified, DESTINATION is expected to be a folder rather than a file. If no TABLEs are specified, sqlexport attempts to execute the SQL statements stored in shell's SQL buffer, and writes the result of queries to DESTINATION. Data written to DESTINATION can be in one of these formats: delimited data, Excel file, or INSERT statements; see -f option for details.
A default file extension is assigned to the DESTINATION file if it does not have one, i.e. if DESTINATION does not contain a dot character. Default extensions are format specific, they are .txt, .xls, .xlsx, and .sql for delimited data, Excel file, Excel 2007 file, and INSERT statements respectively.
If DESTINATION is not supplied, the query result is written to standard output.
OPTIONS
If both short form and long form are specified on the command line, the long form will take precedence.
-c, --charset CHARSET
The character set to be used for encoding output; supported values are: 'UTF-8' and 'platform-default', default to 'UTF-8'.
-d, --database DATABASE
The name of the database from which to look up data, default to the connected database.
-de, --debug
Enabled debug information sent to stderr.
-f, --format FORMAT
The output format; supported values are: 'csv', 'INSERT', 'excel', 'excel2007', default to 'csv'.
-i, --interactive
Prompt before overwriting DESTINATION if it exists and is not a folder.
-k, --session-id SESSION_ID
Use the server connection associated with the session identified by SESSION_ID.
-l, --line-separator LINE-SEPARATOR
The line separator to be used in the output file; supported values are: 'unix', 'windows', default to platforms line separator.
-o, --output-file DESTINATION
The name of the file, or folder if more than one TABLEs are specified, where the query result to be written.
-s, --schema SCHEMA
The name of the schema from which to look up data, default to the currently connected schema.
The following options will take effect if output format is set to 'csv':
-CN, --column-names BOOLEAN
Include or exclude column names as first row, default to 'true'. See BOOLEAN VALUES section below for supported BOOLEAN values.
-DD, --delimiter DELIMITER
The delimiter for separating data; default to ','. Use words 'tab', 'space' for setting tab character, space character, as delimiter respectively.
-DQ, --date-quote IDENTIFIER
Date quoted identifier; supported values are: 'double-quote', 'single-quote', 'square-bracket', 'none', default to 'square-bracket'.
-DS, --decimal-symbol SYMBOL
Decimal symbol; default to '.'.
-NT, --null-text BOOLEAN
Set or not set text to (null) on NULL values, default to 'true'. See BOOLEAN VALUES section below for supported BOOLEAN values.
-PA, --datetime PATTERN
Pattern for formatting date and time, default to 'yyyyMMdd HH:mm:ss.SSS'.
-PD, --date PATTERN
Pattern for formatting date, default to 'yyyyMMdd'
-PT, --time PATTERN
Pattern for formatting time, default to 'HH:mm:ss.SSS'.
The following options will take effect if output format is set to 'INSERT':
-CT, --create-table BOOLEAN
Include or exclude table CREATE as first statement, default to 'false'. See BOOLEAN VALUES section below for supported BOOLEAN values.
-II, --identity-insert BOOLEAN
Enable or disable identity insert, default to 'false'. See BOOLEAN VALUES section below for supported BOOLEAN values.
-TS, --target-schema SCHEMA
The name of the schema to which data to be written, default to the schema from which data is retrieved.
-TT, --target-table TABLE
The name of the table to which data to be written; this option must be specified if no source TABLEs given on the command line, and only takes effect in that context.
BOOLEAN Values:
The following are supported values: 'true', 'false', 'yes', 'no', 'on', 'off', '1', '0'.
EXAMPLE
To export the table Orders with schema dbo from the database Northwind, use the command below. The output format is csv.