Reputation: 43
We're beginners and our java software gets queries from the database using select * etc.
My question is do we need to add lock in share mode and "FOR UPDATE" to enforce the locks, or are table and row locks automatic?
We have one table where we want to enforce concurrency, could I just add LOCK TABLE to the table i need to lock, update then values, then unlock it?
Upvotes: 0
Views: 1705
Reputation: 71422
I would think that based on your answers to my comments, you really shouldn't have to worry about manually handling table locks. InnoDB supports row-level locking and with autocommit enabled (as it is by default) all individual queries are actually handled in a transactional manner.
Now if you have multiple SQL queries that need to be handled as a single transaction (i.e. update one table, then update another table - either both succeed or both get rolled back) then you would need to specifically start a transaction and either commit it or roll it back after the provisional queries have been executed.
You can also use SET TRANSACTION
statement if you need to change the transaction isolation level (it is `REPEATABLE READ1 by default).
For more information check out the MySQL Documentation
Upvotes: 2