1. Home
  2. Troubleshooting
  3. Installation Issues
  4. Executing SQL Server commands without SSMS

Executing SQL Server commands without SSMS

In cases where the SSMS (SQL Server Management Studio) is not installed and we have to execute SQL Server commands, it can be done using the command prompt.

It can be relevant to Linux installations where we want to check the instance name or run the script for creating an SQL Server user with minimum permissions.

The basic syntax for running a command is:

sqlcmd -S <server_name> -U <username> -P <password> -Q "<SQL_query>"

Where:

  • server_name is the name or IP address of the SQL Server instance you want to connect to.
  • username is the username to use when connecting to the instance.
  • password is the password for the username specified.
  • SQL_query is the SQL command or query you want to execute.

Note that the -Q flag is used to specify that the command following it is a SQL query or command.

For example, to connect to a SQL Server instance named “MyServer” with the username “sa” and password “mypassword”, and execute the query “SELECT * FROM Customers”, you would use the following command:

sqlcmd -S MyServer -U sa -P mypassword -Q “SELECT * FROM Customers”

Was this article helpful?