Start Mysql updating multiple rows

Mysql updating multiple rows

The transaction will implement line blocking of that row using the update statement at the beginning, so that the other requests can only update the same row after the transaction completion report is returned. However, it may be refused by the architect during code review if we open a transaction so casually just for such a small requirement.

Instead, it may be subject to another update statement, so that the user can feel the enthusiasm of other users during the period when the database begins to execute the update statement, and during the period when the update statement is executed until the select statement starts to be executed.

We can't use our example as there is only creation date of the first insert. If we named our index we can simply execute this query to remove the unique key: date.

Let's say that we want to have daily statistics for each article. First of all we have to delete our previous key as it won't be needed anymore.

So this condition will be true and Keep in mind, that on first insert, when there's no record in the table, insert will be performed.

It means that all code after ON DUPLICATE KEY UPDATE won't be executed.

Well, the user experience is really a useful imperial sword.

So the back-end engineer writes such an SQL statement: update likes set gmt_modified = now(), count = count 1 where object_id = ? ; Then the liking API that provides the basic functionality can be worked out!

It will be as simple as possible, I just want to show You how to use ON DUPLICATE KEY UPDATE:) CREATE TABLE `stats` ( `id` int(11) NOT NULL AUTO_INCREMENT, `article_id` int(11) NOT NULL, `views_count` int(11) NOT NULL DEFAULT '1', `created` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=Inno DB DEFAULT CHARSET=utf8 field by 1. Let's take a look at this example: INSERT INTO stats (article_id, created) VALUES (12, CURRENT_DATE()) ON DUPLICATE KEY UPDATE views_count = IF(VALUES(article_id) = 12, views_count 2, views_count 1) /*, additional_field = additional_field 1, next_field = IF(article_id = 1, 1, 0). It has three parts, condition, value if true, value if false.