MySQL updates the same row by multiple users, such as counter

I am trying to increase the counter for user messages. The message in my MySQL table has a field like that shows how much you like this particular post. Now, what happens if multiple users like the same post at the same time? I think this will lead to conflict or will not increase correctly? How can I avoid this, do I need to block the row or what parameters do I have?

my query might look something like this:

UPDATE posts
    SET likes = likes + 1,
    WHERE id = some_value

also, when the user does not access the message, it should decrease → like -1

Thanks for any help!

+4
source share
3 answers

:

UPDATE mytable SET mycolumn = mycolumn + 1;

, , , .

, , , , , , .

+3

-, , .

, SQL .

UPDATE posts
SET likes = likes + 1
WHERE id = some_value

, . , 0 2.

someTableAdapter.LikePost(postID);
someTableAdapter.LikePost(postID);
+3

, , (, , ). , , ). , , - . MySQL.

MySQL 5.1:

YouTube: MySQL


"MySQL InnoDB , , OLTP-.

MySQL MyISAM, MEMORY MERGE, , , . "

MySQL, 8.7.1:


, , InnoDB, , , ACID, .

, , , .

+2

Source: https://habr.com/ru/post/1543074/


All Articles