Lock row in SQL Server table

I need to lock a row in a table so that no one can read this row while I execute the procedure. I use BEGIN TRANin this procedure. So this entry that I am trying to lock is not executed during the process. Is it possible?

+4
source share
1 answer

Depending on the purpose of your stored procedure:

- If it changes the specified line, you can rely on transaction levels

INSTALLED BET INSULATION LEVEL

START TRANSFER

- UPDATE / INSERT / DELETE your row here

...

COMMIT TRANSACTION SET THE INSULATION LEVEL PICTURES RE-READ

-

SELECT column1, column2

FROM yourTable WITH (ROWLOCK)

ID = YourRecordId

...

COMMIT TRANSACTION

0

All Articles