Posts

Showing posts from October, 2013

Kill All connection of a database

If you want to kill all the connection of a database at once then use below query. you have to write your database name in place of DatabaseName (written in the below query) USE master; GO ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE DatabaseName SET MULTI_USER; GO

SQL query for finding dead locks on tables of a database

SELECT  L.request_session_id AS SPID,     DB_NAME(L.resource_database_id) AS DatabaseName,     O.Name AS LockedObjectName,     P.object_id AS LockedObjectId,     L.resource_type AS LockedResource,     L.request_mode AS LockType,     ST.text AS SqlStatementText,           ES.login_name AS LoginName,     ES.host_name AS HostName,     TST.is_user_transaction as IsUserTransaction,     AT.name as TransactionName,     CN.auth_scheme as AuthenticationMethod FROM    sys.dm_tran_locks L     JOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_id     JOIN sys.objects O ON O.object_id = P.object_id     JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id     JOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_id     JOIN sys.dm_tran_active_tra...