Select with Update

3

Would anyone know if there is a SQL layer to run a SELECT using LOCK IN SHARE MODE in the registry and running an UPDATE at the same time? example:

SELECT * FROM Nome_Tabela WHERE id = 5 LOCK IN SHARE MODE (UPDATE AQUI)

Any suggestions? I'm using MySQL.

    
asked by anonymous 21.07.2015 / 19:16

1 answer

1

If you intend to "lock" in the registry so that no one changes before you do your update, I recommend using FOR UPDATE strong>.

Example:

SELECT nome FROM clientes WHERE nome = 'josé' FOR UPDATE; UPDATE clientes SET nome = 'josé das couves';

Reference MySql .

    
18.02.2016 / 19:55