Home > Database > Mysql Tutorial > How Python operates MySQL to create time and update time

How Python operates MySQL to create time and update time

WBOY
Release: 2023-05-31 10:49:31
forward
1270 people have browsed it

Creation time, update time

DEFAULT CURRENT_TIMESTAMP
--表示当插入数据的时候,该字段默认值为当前时间
 
ON UPDATE CURRENT_TIMESTAMP
--表示每次更新这条数据的时候,该字段都会更新成当前时间
Copy after login

These two operations are maintained by the mysql database itself. You can generate two fields [creation time] and [update time] based on this feature. , and does not require code to maintain.

CREATE TABLE `test` (
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Copy after login

The above is the detailed content of How Python operates MySQL to create time and update time. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template