top of page

ABOUT "ROWLOCK"

ROWLOCK specifies that row locks are taken when page or table locks are ordinarily taken. When specified in transactions operating at the SNAPSHOT isolation level, row locks are not taken unless ROWLOCK is combined with other table hints that require locks, such as UPDLOCK and HOLDLOCK.

 

Here is an example:

You need to create a stored procedure named spDeleteCategory to delete records in the database. The stored procedure must meet the following requirments:

1. Delete records in both the BlogEntry and BlogCategory tables where CategoryId equals parameter @CategoryId. 2. Avoid locking the entire table when deleting records from the BlogCategory table. 3. If an error occurs during a delete operation on either table, all changes must be rolled back, otherwise all changes should be committed.

 

This stored procedure can be written as follows,

CREATE PROCEDURE spDeleteCategory

(@CategoryID int)

AS

BEGIN

SET NOCOUNT ON

SET Implicit_Transactions ON

Begin try

DELETE FROM BlogEntry WHERE CategoryID = @CategoryID

DELETE FROM BlogCategoryWITH ROWLOCK WHERE CategoryID = @CategoryID

IF @@TRANSACTION > 0

COMMIT TRANSACTION;

End try

Begin catch

IF @@TRANSACTION > 0

ROLLBACK TRANSACTION;

END catch

END

aboutME

I am John Fan Zhang, a data analyst and finance researcher. I hold a PhD in finance, CFA charter and full membership of CFA New Zealand Society. I have fifteen-year experience in corporate investment and eight-year experience in advanced data analysis. My research focuses on the effect of social psychology (culture) on financial decisions. Finance research involves heaps of data analyses that lead me to the data field. I am a Microsoft Certified Solutions Expert (MCSE): Data Management and Analytics (Excel, Power BI, and SQL). Aside from Excel, Power BI and SQL, I am also familiar with econometric tools such as Stata, Eviews, and MATLAB. I use OX and Python for programming. I am an active data community event participant, volunteer, speaker, moderator, program reviewer, including PASS Marathon 2020, Global AI BootCamp Auckland 2019, SQL Saturday Auckland (2017, 2018, 2019), and Definity Conference (2018, 2019, 2020, Auckland, New Zealand).

Auckland, New Zealand

  • Google Site
  • Twitter
  • LinkedIn

©2016 BY JOHN'S DATA STORY

bottom of page