Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet370/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   366   367   368   369   370   371   372   373   ...   443
Bog'liq
BookSQL

 

CHAPTER 9

 

Transactions and Concurrency



 

 335

2-6d

Run the following code in Connection 2, which is now running under the READ COMMITTED 



SNAPSHOT isolation level because the database flag READ_COMMITTED_SNAPSHOT is turned 

on. Notice that you’re not blocked—instead, you get an earlier, consistent version of the data 

that was available when the statement started (with discount values of 0.00).

BEGIN TRAN; 

 

  SELECT orderid, productid, unitprice, qty, discount 



  FROM Sales.OrderDetails 

  WHERE orderid = 10249;



2-6e

Go to Connection 1 and commit the transaction.

COMMIT TRAN;

2-6f

Go to Connection 2, query the data again, and commit the transaction; notice that you get the new 

discount values of 0.05.

  SELECT orderid, productid, unitprice, qty, discount 

  FROM Sales.OrderDetails 

  WHERE orderid = 10249; 

 

COMMIT TRAN;



2-6g

Run the following code for cleanup.

UPDATE Sales.OrderDetails 

  SET discount = 0.00 

WHERE orderid = 10249;

Close all connections.



2-6h

If you are running against an on-premises SQL Server instance, change the database flags back to the 

defaults, disabling isolation levels based on row versioning.

ALTER DATABASE TSQL2012 SET ALLOW_SNAPSHOT_ISOLATION OFF; 

ALTER DATABASE TSQL2012 SET READ_COMMITTED_SNAPSHOT OFF;

Exercise 3 (steps 1 through 7) deals with deadlocks.

www.it-ebooks.info



336  

Microsoft SQL Server 2012 T-SQL Fundamentals



3-1

Open two new connections. (This exercise will refer to them as Connection 1 and Connection 2.)



3-2

Run the following code in Connection 1 to open a transaction and update the row for product 2 in 



Production.Products.

BEGIN TRAN; 

 

  UPDATE Production.Products 



    SET unitprice += 1.00 

  WHERE productid = 2;



3-3

Run the following code in Connection 2 to open a transaction and update the row for product 3 in 



Production.Products.

BEGIN TRAN; 

 

  UPDATE Production.Products 



    SET unitprice += 1.00 

  WHERE productid = 3;



3-4

Run the following code in Connection 1 to query product 3. You will be blocked. (Remember to un-

comment the hint if you are connected to SQL Database.)

  SELECT productid, unitprice 

  FROM Production.Products -- WITH (READCOMMITTEDLOCK) 

  WHERE productid = 3; 

 

COMMIT TRAN;



3-5

Run the following code in Connection 2 to query product 2. You will be blocked, and a deadlock error 

will be generated either in Connection 1 or Connection 2.

  SELECT productid, unitprice 

  FROM Production.Products -- WITH (READCOMMITTEDLOCK) 

  WHERE productid = 2; 

 

COMMIT TRAN;



www.it-ebooks.info



Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   366   367   368   369   370   371   372   373   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish