Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How do you simulate a deadlock for testing purposes



How do you simulate a deadlock for testing purposes..

Answer / jay

Below is a quick recipe for a dead lock. Two transactions,
one first updating table 1, then 2 and the other one doing
it in reverse order.

Both transactions wait in the middle for 20 seconds to give
you some time to execute them 'simulaneously'.

When you run the two in transactions in two windows 'at the
same time', you'll only have to wait ~20 seconds, and one of
the windows will experience a dead lock.




CREATE TABLE t1 (i int);
CREATE TABLE t2 (i int);

INSERT t1 SELECT 1;
INSERT t2 SELECT 9;


/* in one window enter: */
BEGIN TRAN
UPDATE t1 SET i = 11 WHERE i = 1
WAITFOR DELAY '00:00:20'
UPDATE t2 SET i = 99 WHERE i = 9
COMMIT

/* in a second window (another transaction) enter: */
BEGIN TRAN
UPDATE t2 SET i = 99 WHERE i = 9
WAITFOR DELAY '00:00:20'
UPDATE t1 SET i = 11 WHERE i = 1
COMMIT

Is This Answer Correct ?    8 Yes 1 No

Post New Answer

More SQL Server Interview Questions

What is difference between Datepart() and Datename() in SqlServer?

0 Answers   Infosys,


A trigger can reference objects outside the current database? State true or false.

0 Answers  


What is database black box testing?

0 Answers  


What is a Join and explain its types?

0 Answers  


What is the use of sign function?

0 Answers  


what kind of lan types do you know? : Sql server database administration

0 Answers  


query processing

0 Answers  


Explain the phases a transaction has to undergo?

0 Answers  


What is mean by "fill factor" ? and what is mean by "Index "in sql?

1 Answers   iGate, Logica CMG,


How to loop through result set objects using odbc_fetch_row()?

0 Answers  


what is the difference between openrowset and openquery?

0 Answers  


If i am handling 150 servers then how to check the active jobs of all the servers?

0 Answers  


Categories