Sql Server - sqlcmd

1 - About

The command line tool of SQL Server.

2.1 - Installation

3 - Management

3.1 - Connect

  • Connect as SA

sqlcmd -S localhost -U SA -P pwd

3.2 - Quit

  • Quit

quit

3.3 - 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
    );
"

3.4 - 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

Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap