MySql的CURRENT_TIMESTAMP
CREATE TABLE `table_name` ( `id` int(11) NOT NULL AUTO_INCREMENT, `project_id` int(11) NOT NULL, `pdf_id` char(32) COLLATE utf8mb4_bin NOT NULL, `user_id` int(11) NOT NULL, `last_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `IDX_PROJECT_PAPER_USER` (`project_id`,`pdf_id`,`user_id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=41836 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
DEFAULT CURRENT_TIMESTAMP
表示当插入数据的时候,该字段默认值为当前时间
ON UPDATE CURRENT_TIMESTAMP
表示每次更新这条数据的时候,该字段都会更新成当前时间
插入一条数据:
INSERT INTO paper_xxxx (project_id, pdf_id, user_id) VALUES (%s,%s,%s) ON DUPLICATE KEY UPDATE last_view_time = CURRENT_TIMESTAMP