Thursday, 27 October 2016

How to close all active connections to MS SQL database


Query to close all active connections to MS SQL database:

use master
go
alter database PrimumII_LoadTest
set single_user with rollback immediate
go
alter database PrimumII_LoadTest
set multi_user
go

How to lock a table in MSSQL

Query lock a table in MSSQL:

BEGIN TRAN
SELECT 1 FROM <Table Name> WITH (TABLOCKX)
WAITFOR DELAY '00:11:00'
ROLLBACK TRAN  
GO