MS SQL - Mimicking a busy table
Sometimes you want to test a query being unable to access a table that is part of a query (suppose you are using an ORM like Entity Framework <- which sucks ) and a reasonably quick way I have found to make the table appear busy or unavailable is to lock the entire table for a period of test time in this case 2 minutes
BEGIN TRAN SELECT TOP (1) 1 FROM [dbo].[TargetTable] WITH (TABLOCKX) WAITFOR DELAY '00:02:00' ROLLBACK TRAN GO
TABLOCKX Specifies that an exclusive lock is taken on the table.