Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use FOR UPDATE in SQL Queries? [duplicate]

Tags:

php

mysql

Can anyone please tell the difference between the following sql,

SELECT * FROM TABLE

VS

SELECT * FROM TABLE FOR UPDATE

When and at what situation i need to use For Update

It is taking more time for getting the data if i use update and getting stopped. What is happening on Update to increase the time. Please tell me the entire process happening on this.

like image 579
Vinoth Babu Avatar asked Nov 22 '25 15:11

Vinoth Babu


1 Answers

I think the sentence from the MariaDB / MySQL manual is self-explanatory:

If you use FOR UPDATE with a storage engine that uses page or row locks, rows examined by the query are write-locked until the end of the current transaction.

like image 76
DejanLekic Avatar answered Nov 24 '25 05:11

DejanLekic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!