Search code snippets, questions, articles...

sqlcmd command to connect to a SQL server

The sqlcmd command is used to connect to a SQL server. This command can be used to run queries, create databases, and perform other tasks. In this post, we will learn how to connect to a SQL server using sqlcmd.
sqlcmd -S host_url -U user_name -P password

-- Example to connect to an AWS RDS
sqlcmd -S -U sa -P pass@123
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the above sqlcmd command:


user: sa

password: pass@123

If the sqlcmd command is successful and the connection is made with the server then you will see the output as below.

root@ sqlcmd -S host_url -U user_name -P password

Get all Databases on SQL Server

After making a connection with the SQL Server you can list all the databases by executing the below query in sqlcmd.

1>SELECT name, database_id, create_date
2>FROM sys.databases;
Was this helpful?