MySql的CURRENT_TIMESTAMP

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

 

上一篇:MySQL插入异常:SQL state [HY000]; error code [1366]-----(utf8mb4)


下一篇:php artisan migrate时出现 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was to