forked from lyhabc/SQLServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirtyReadingandPrevention.sql
36 lines (23 loc) · 1.01 KB
/
DirtyReadingandPrevention.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Data dirty reading: consistency and locking
Helpful article: http://blog.sqlauthority.com/2012/11/15/sql-server-concurrency-basics-guest-post-by-vinod-kumar/ by Vinod Kumar
*/
-- Pessimistic concurrency - frequent blocking, increased consistency
-- Optimistic concurrency - little blocking, decreased consistency
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
-- Helpful information table
DECLARE @dirty TABLE(
[Details] VARCHAR(50),
[Read Uncommitted] VARCHAR(50),
[Read Committed] VARCHAR(50),
[Repeatable Read] VARCHAR(50),
[Snapshot] VARCHAR(50),
[Serializable] VARCHAR(50)
)
INSERT INTO @dirty VALUES ('ISOLATION LEVEL:','Optimistic','Both','Pessimistic','Optimistic','Pessimistic')
INSERT INTO @dirty VALUES ('BEHAVIOR - DIRTY READS:','Yes','No','No','Yes','No')
SELECT * FROM @dirty