Sql Server - sqlcmd

About

The command line tool of SQL Server.

Installation

Management

Connect

  • Connect as SA
sqlcmd -S localhost -U SA -P pwd

Quit

  • Quit
quit

Execute an inline-script

sqlcmd.exe -S <server name> -d <database name> -U <username> -P <password> -I -Q "
    CREATE TABLE DimDate2
    (
        DateId INT NOT NULL,
        CalendarQuarter TINYINT NOT NULL,
        FiscalQuarter TINYINT NOT NULL
    )
    WITH
    (
        CLUSTERED COLUMNSTORE INDEX,
        DISTRIBUTION = ROUND_ROBIN
    );
"

Dump from Azure

sqlcmd `
   -S sqlpap0017t.database.windows.net `
   -d Adventureworkstest `
   -U user `
   -P password `
   -s ',' `
   -W  `
   -Q "SELECT * FROM myTable" `
   > MyTable.csv
 

where:

  • s is the separator
  • S is the server
  • d is the database name
  • W suppress trailing space

Powered by ComboStrap