Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 can anyone give me two queries which will cause de

Author  Topic 

nishita_s
Yak Posting Veteran

61 Posts

Posted - 2008-12-16 : 05:18:48
can anyone give me two queries which will cause deadlock??

chrianth
Yak Posting Veteran

50 Posts

Posted - 2008-12-16 : 08:52:33

deadlock occurs when two or more long running or complex queries are accessing same tables.

to prevent deadlock you can put WITH(NOLOCK) after your table name or table alias..
Go to Top of Page

JamesRyan
Starting Member

18 Posts

Posted - 2008-12-16 : 10:02:38
From http://www.sqlservercentral.com/articles/Administering/perfmonexcerpt/757/

http://www.sqlhowto.co.uk/post/how-can-i-force-a-deadlock-in-sql-.html
To create a deadlock event on your own, open two connections in Query Analyzer to a server. For our example, we?ll use the Northwind database. In one connection, we?ll enter the following code:

-- BEGIN TRAN
/*
UPDATE Customers
SET CompanyName = 'Doe, Inc'
*/
-- SELECT * FROM Employees
-- ROLLBACK TRAN

In the other connection, we?ll place the following code:

-- BEGIN TRAN
/*
UPDATE Employees
SET LastName = 'Doe'
*/
-- SELECT * FROM Customers
-- ROLLBACK TRAN

The idea here is we?re going to have one connection create an exclusive table lock on the Customers table. The other connection will create an exclusive table lock on the Employees table. Then the first connection will try and select from the Employees table. Since the second connection has an exclusive table lock and the transaction isn?t committed, it?ll be blocked. Then we?ll have the second connection try and select from the Customers table. It too will get blocked and SQL Server will realize that we?ve run into a deadlock situation.

James Ryan
www.sqlhowto.co.uk
Go to Top of Page

nishita_s
Yak Posting Veteran

61 Posts

Posted - 2008-12-17 : 03:24:33
Thats great finally i got that error. thanx James
Go to Top of Page
   

- Advertisement -