Continuation of this topic ! There is a table:
CREATE TABLE IF NOT EXISTS `TABLE_KITS_LOG` ( `FIELD_SERVER_ID` varchar(64) COLLATE utf8_unicode_ci, `FIELD_PLAYER` varchar(64) COLLATE utf8_unicode_ci, `FIELD_KIT_NAME` varchar(64) COLLATE utf8_unicode_ci, `FIELD_TIMESTAMP` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; For her, there is an index:
CREATE unique index TABLE_KITS_LOG_INDEX on TABLE_KITS_LOG( FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME); For example, in the table there is a trace record:
INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME) VALUES ("rpg", "name", "deluxe"); INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME) VALUES ("rpg", "name", "mods"); INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME) VALUES ("rpg", "name", "vip"); INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME) VALUES ("classic", "name", "deluxe"); INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME) VALUES ("classic", "name", "mods"); INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME) VALUES ("classic", "name", "vip"); Since the change only requires the FIELD_TIMESTAMP field FIELD_TIMESTAMP I try to make a query that, using a unique index and table settings, will update this field itself, because when I create a table, I specify the default value and value when updating CURRENT_TIMESTAMP .
Since I indicated that when the record is updated, the FIELD_TIMESTAMP column should update itself, I do not know what to write after the KEY UPDATE , in the version that the error is written below: Error Code: 1136. Column count doesn't match value count at row 1 . It should be noted that if there is no record, then it needs to be inserted, and if there is, update the time.
Attempt to make the necessary request:
INSERT INTO `TABLE_KITS_LOG` (FIELD_SERVER_ID, FIELD_PLAYER, FIELD_KIT_NAME, FIELD_TIMESTAMP) VALUES ("rpg", "name", "mods") ON DUPLICATE KEY UPDATE FIELD_TIMESTAMP = CURRENT_TIMESTAMP; @Akina help
INSERT INTO table_kits_log (field_server_id, field_player, field_kit_name) VALUES ("rpg", "name", "mods") ON DUPLICATE KEY UPDATE field_kit_name=VALUES(field_kit_name);- Akinafield_kit_name=VALUES(field_kit_name)specified in this case? - Prototype - TV