· 8 years ago · Feb 07, 2018, 11:46 PM
1--Create a test database.
2CREATE DATABASE myDatabase
3
4--Change database context.
5USE myDatabase
6GO
7
8--Create a test table.
9DROP TABLE IF EXISTS myTable
10CREATE TABLE myTable ( firstname VARCHAR(25), surname VARCHAR(25), email VARCHAR(50) )
11
12--Start explicit transaction but do not commit.
13BEGIN TRANSACTION
14INSERT INTO myTable VALUES ( 'pete', 'whyte', 'myemail@address.com' )
15--COMMIT
16
17
18/*
19--Now run a select statement in a new query window on the table we have just created.
20--The insert has a lock on the table until committed, so it'll continue to execute.
21--Open another query window (or you can come back to this one) and run sp_whoisactive.
22*/
23
24USE [DBTools]
25GO
26sp_whoisactive