SQL allocate record (RowLock)

0

I'm developing an application, and I'm facing a problem about registry competition.

What happens is that I have several people who can access the same record, so I needed that when a user clicked edit, I would allocate that record.

Finding that there is rowlock but I can not even put this parameter, I can still change the line.

In the example below, I want to block the line whose id corresponds to 1099, but even doing so, if I run a UPDATE it executes successfully.

SELECT * FROM crm_man WITH (holdlock,rowlock)
WHERE id = 1099
    
asked by anonymous 26.09.2016 / 18:18

1 answer

0

When working with lock's we need to make explicit the start of the command and the end:

begin tran //inicio do comando

select * from crm_man with (holdlock,rowlock)
where id = 1099    

commit // fim do comando

In the above case, as long as the command commit is not executed, lock will be active, and no update or change of line will be executed.

    
26.09.2016 / 18:43