Sql Server - sqlcmd

Card Puncher Data Processing

About

The command line tool of SQL Server.

Installation

see SQL Server - mssql-tool

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





Discover More
Sql Server New Database Studio
SQL Server - Database

GUI Command line (sqlcmd)
Card Puncher Data Processing
SQL Server - Variable

SQL Server - Variable



Share this page:
Follow us:
Task Runner