You can connect to a SQL Server instance using either the GUI (SQL Server Management Studio) or the CLI (Command Line Interface).
We’ll demonstrate connecting to the instance using the command line in this tutorial.
Ensure that your instance service is active. You can see it in your window’s “Services” section. You can choose the service and click on start if the SQL Server database engine service is not running. If you want the SQL Server agent to run, you can similarly do this with the agent service.
Connecting through CLI
To connect to SQL Server through Windows Authentication.
sqlcmd -S MyPC\MSSQLSERVER2014 -E
-E is to specify a trusted connection
-S is to specify SQL Server name of the instance.
Replace “MyPC\MSSQLSERVER2014” with the name of the computer and the instance of SQL Server that you want to connect to.
If you are connecting to the default instance then you just specify the instance name.
Eg: sqlcmd [ /E ] [ /S servername ].
If you are connecting to the named instance then you must specify the computer and instance name. Eg: sqlcmd [ /E ] /S servername\instancename
To connect to SQL Server through SQLServer Authentication.
sqlcmd -S MyPC\MSSQLSERVER2014 -U shaiks -P PassWord
The –S value is to specify the SQL Server name of the instance and -E is to specify a trusted connection. If you do not specify the SQL Server name, it will try to connect to the local machine.
To end the sentence it is required to provide “GO“.
Hope you find this article helpful.