To create a deadlock:
[ol]
[li]Both the following occur:[ul][li]Acquire a lock on a row in Query Analzyer session A.[/li]
[li]Acquire a lock on a row in the same table in session B.[/li][/ul]
[/li]
[li]Then, both the following occur:[ul][li]Attempt to escalate the lock in session A to a table lock.[/li]
[li]Attempt to escalate the lock in session B to a table lock.[/li][/ul]
[/li]
[/ol]
The order of the items under each number is unimportant. At the first action in part 2, a block will occur and the session will wait until the lock from the other session is released.
At the second action in part 2, both processes now have resources locked that block the other from continuing. Unless the server detects this deadlock and kills one process (and rolls it back), the mutual block/lock would never end, locking resources forever.
You could also use two tables instead of one table with escalating lock size:
[ol]
[li]Both the following occur:[ul][li]Session A locks table X.[/li]
[li]Session B locks table Y.[/li][/ul]
[/li]
[li]Then, both the following occur:[ul][li]Session A requests lock on table Y.[/li]
[li]Session B requests lock on table X.[/li][/ul]
[/li]
[/ol]
Deadlock.
[COLOR=black #e0e0e0]For SQL and technical ideas, visit my blog,
Squared Thoughts.
The best part about anything that has cheese is the cheese.[/color]