SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Testing Deadlock Conditions


Testing Deadlock Conditions

Author
Message
EddieN1
EddieN1
SSC-Enthusiastic
SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)

Group: General Forum Members
Points: 188 Visits: 46
Can someone suggest a way I can intentionally create a Deadlock condition for testing? I'm running SQL Server Express 2012.
Bill Talada
Bill Talada
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7092 Visits: 2296
In SSMS, open three sheets and run sheet 0. Then run sheet 1 and 2 within 10 seconds of each other.
Remember to do rollbacks in sheets 1 and 2 after failure.


-- sheet 0
CREATE TABLE t1 (i int);
CREATE TABLE t2 (i int);
GO
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);
GO
SELECT * FROM t1;
SELECT * FROM t2;
GO

-- sheet 1
BEGIN TRAN
UPDATE t1 SET i = 10;
WAITFOR DELAY '00:00:10';
UPDATE t2 SET i = 20;
COMMIT TRAN
-- rollback

-- sheet 2
BEGIN TRAN
UPDATE t2 SET i = 22;
WAITFOR DELAY '00:00:10';
UPDATE t1 SET i = 11;
COMMIT TRAN
-- rollback



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search