In some cases, SSMS (SQL Server Management Studio) is not installed on the server and you may need to connect to SQL Server from the cmd command line immediately.
In this case, you should run cmd by right-clicking the command line and clicking run as administrator to connect to the sql server. Then you can connect to SQL Server with the help of the following command.
sqlcmd -E -S .\TESTINSTACE2
|.\||It represents your current server. You can write hostname\ instead instead of this.|
|TESTINSTACE2||Name of Named instance|
|-E||It means Trusted Connection. Do not change this.|
|-S||It means Server. Do not change this.|
If you want to connect to default instance instead of named instance, you can connect by typing sqlcmd only.
Queries that you run after connecting from the cmd command line must be specific. You should not run with “
Select * From...“. If you run this way, it will be difficult to read the incoming query result.
For example, you should only select the column you need, such as “
Select name From sys.databases“.
You can use the following script to view the current summary of queries (if there is a lock or not).
select r.blocking_session_id,DB_NAME(r.database_id) as DatabaseName,text from sys.dm_exec_requests r
inner join sys.dm_exec_sessions s on r.session_id = s.session_id
cross apply sys.dm_exec_sql_text(r.sql_handle) t where r.session_id <> @@SPID