gsqlcmd SQL Options

gsqlcmd SQL Options

/columnNameQuote=[<quote>]

Use this option to set or disable column name quotes in generated SQL commands.

gsqlcmd uses server-specific quotes by default: square brackets for SQL Server and SQL Server Compact, backticks for MySQL, and double quotes for other servers.

/[commands=]insert | update | delete | merge

Use this option to specify generated commands in the make and import modes.

For example:

gsqlcmd make yahoo.db 1min-aapl.csv *-insert.sql /insert /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-update.sql /update /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-delete.sql /delete /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-merge.sql  /merge  /table=yahoo1min /echoOutputFileName

The default option is /insert.

Use the /insert option (or omit it) to generate commands to execute stored procedures or custom code.

For example:

gsqlcmd make yahoo.db 1min-aapl.csv *-custom.sql /insert /table=custom-code.sql /echoOutputFileName

Note, you can define columns used in the WHERE clause using the /keys option like

gsqlcmd make yahoo.db 1min-aapl.csv *-insert.sql /insert /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-update.sql /update /table=yahoo1min /echoOutputFileName /keys=symbol,time
gsqlcmd make yahoo.db 1min-aapl.csv *-delete.sql /delete /table=yahoo1min /echoOutputFileName /keys=symbol,time
gsqlcmd make yahoo.db 1min-aapl.csv *-merge.sql  /merge  /table=yahoo1min /echoOutputFileName /keys=symbol,time

/groupSize=<number of rows>

Use this option to define the number of rows separated by the GO batch separator.

/insertIdentity

Use this option to include identity columns into INSERT and MERGE commands generated in the make and import modes.

/insertNulls

Use this option to keep NULL values in INSERT commands generated in the make and import modes.

/keys=<field>[;...]

Use this option to define primary key fields in the make-create mode.

For example:

gsqlcmd make-create data.csv create-table.sql /table=dbo.data /mssql /keys=FirstName,LastName

Also, use this option to define fields to use in the WHERE clause of generated UPDATE and DELETE commands in the make and import modes.

For example, you can use this option to synchronize data between different databases using fields like email or SSN instead of primary key fields.

For example:

gsqlcmd make db emails.csv merge.sql /merge /table=dbo.emails /keys=email

/objectNameQuote=[<quote>]

Use this option to set or disable object name quotes in generated SQL commands.

gsqlcmd uses server-specific quotes by default: square brackets for SQL Server and SQL Server Compact, backticks for MySQL, and double quotes for other servers.

/printTotals[=true | false]

Use this option add a line with the total count of generated SQL commands.

/table=<table | view | stored procedure | SQL template file>

Use this option to define the target database table, view, stored procedure, or SQL template file for code generation.

For example:

gsqlcmd make db data.csv insert.sql /insert /table=dbo.payments

This option is obligatory in the import, make, and make-create modes.

/truncate

Use this option to use the truncate() method instead of delete() in the Knex seed files generated in the make mode.