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.
| 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.. |
 |
|
|
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-.htmlTo 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 CustomersSET CompanyName = 'Doe, Inc'*/-- SELECT * FROM Employees-- ROLLBACK TRANIn the other connection, we?ll place the following code:-- BEGIN TRAN/*UPDATE EmployeesSET LastName = 'Doe'*/-- SELECT * FROM Customers-- ROLLBACK TRANThe 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 Ryanwww.sqlhowto.co.uk |
 |
|
|
nishita_s
Yak Posting Veteran
61 Posts |
Posted - 2008-12-17 : 03:24:33
|
| Thats great finally i got that error. thanx James |
 |
|
|
|
|
|