Monday, March 19, 2012

Deadlock in single session

Hi guys,
I need to stimulate a deadlock senerio in sql server.. i know i can do
it by openning two sessions of query analyzer.. is there any way of
creating a deadlock with a sigle session..
thanks to all in advance..This section of the SQL2005 BOL discusses, among other things, two tasks in
the same session causing a deadlock:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/2ed3e3e7-5080-4fa3-b79a-585470602bc2.htm
But I have not tried to create such a deadlock myself.
Linchi
"ameen.abdullah@.gmail.com" wrote:
> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>|||Hi
Dan Guzman has written this example
-- session 1
CREATE TABLE MyTable
(
Col1 int NOT NULL
CONSTRAINT PK_MyTable PRIMARY KEY,
Col2 int NULL
)
INSERT INTO MyTable VALUES(1, NULL)
INSERT INTO MyTable VALUES(2, NULL)
GO
BEGIN TRAN
UPDATE MyTable SET Col2 = 1 WHERE Col1 = 1
GO
-- session 2
BEGIN TRAN
UPDATE MyTable SET Col2 = 2 WHERE Col1 = 2
GO
-- session 1
UPDATE MyTable SET Col2 = 3 WHERE Col1 = 2
GO
-- session 2
UPDATE MyTable SET Col2 = 4 WHERE Col1 = 1
GO
---
Connection 1: BEGIN TRAN
Connection 2: BEGIN TRAN
Connection 1: UPDATE id_Test 1
Connection 2: UPDATE id_Test 2
Connection 1: UPDATE id_Test 2 (waits for Connection 2 to COMMIT)
Connection 2: UPDATE id_Test 1 (waits for Connection 1 to COMMIT)
<ameen.abdullah@.gmail.com> wrote in message
news:1151513128.507479.134950@.y41g2000cwy.googlegroups.com...
> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>

No comments:

Post a Comment