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_nameis the name or IP address of the SQL Server instance you want to connect to.usernameis the username to use when connecting to the instance.passwordis the password for the username specified.SQL_queryis 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”
—