Sql rowlock in select statement

I have an ASP.Net webpage where the user selects a row to edit. I want to use row lock on this row, and as soon as the user finishes editing and updates another user, you can edit this row. I. How can I use rowlock so that only one user can edit a row?

thank

+5
source share
2 answers

You cannot lock such a row using the database engine locks.

Most other strategies will rely on maintaining an open connection (e.g. sp_getapplock), and this is pointless in web applications.

, , ?

timestamp/rowversion .

+4

sql select statement.

BEGIN TRAN

SELECT *
FROM   authors AU
WITH   (HOLDLOCK, ROWLOCK)
WHERE  AU.au_id = '274-80-9391'

/* Do all your stuff here while the row is locked */

COMMIT TRAN

HOLDLOCK SQL Server . ROWLOCK SQL Server , .

, , SQL Server , , , .

SELECT id From mytable WITH (ROWLOCK, UPDLOCK) WHERE id = 1 

, . https://www.mssqltips.com/sqlservertip/1257/processing-data-queues-in-sql-server-with-readpast-and-updlock/

+3

All Articles