1. Home
  2. Settings
  3. Linux OS Settings
  4. Executing SQL Server commands without SSMS

Executing SQL Server commands without SSMS

If the SSMS (SQL Server Management Studio) is not installed and you have to execute SQL Server commands, you can do so using the command prompt.

This is especially relevant to Linux installations, where we want to check the instance name or run the script to create 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?