SQLCMD utility to connect SQL Server using command line

Is it possible to connect SQL server with some other tools ? Answer is yes, SQLCMD is the command line tool used to connect SQL Server.

SQLCMD – Simple tool to execute t-sql statment, stored procedures and DML operations. SQLCMD works same as SSMS but without GUI, means you can do all stuff that you do using SSMS but using command line interface. Generally database administrator uses SQLCMD to connect SQL Server instance in dedicated administrator connection to troubleshoot performance. It is light weight tool to connect in case if sql server is not responding and having performance issue.

Default location of SQLCMD utility is : C:\Program Files\Microsoft SQL Server\100\Tools\Binn


This is how I use to connect my SQL server using SQLCMD command with window authentication

SQLCMD -S Servername -E

Servername -> SQL Server database engine name in case of default instance

In case of named SQL Server instance, use below command to connect SQL server database.

SQLCMD -S Dbserver\namedinstance -E

Now using SQL server authentication mode to connect database server

SQLCMD -S Dbserver -U username -P password

SQLCMD -S Dbserver\namedinstance -U username -P password

You can also use port number while connecting to database

SQLCMD -S Dbserver,1433 -U username -P password

Now you connected to the database, execute any select query to verify the access 😉

Leave a Reply




9 − 7 =