简体   繁体   English

MySQL手动更改跟踪

[英]MySQL manual change tracking

I am trying to implement a database change control using MySQL. 我正在尝试使用MySQL实现数据库更改控制。 To control inserts and updates I want to use something similar to a TIMESTAMP field in SQLServer (A column that autoincrements when a insert/update is made over a row). 为了控制插入和更新,我想使用类似于SQLServer中TIMESTAMP字段的内容(当在一行中进行插入/更新时,该列会自动递增)。 Does exists something similar in MySQL? MySQL中是否存在类似的东西? If a want to do it with MySQL my only way is write a trigger for update and another to insert in every table of the database? 如果要使用MySQL做到这一点,我唯一的方法是编写一个更新触发器,并在数据库的每个表中插入另一个触发器?

Thanks 谢谢

Yes you can create your columns like this 是的,您可以像这样创建您的列

CREATE TABLE t1 (
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT ON UPDATE CURRENT_TIMESTAMP
);

The created_at field is set on insert and the updated_at field is automatically updated on update. created_at字段在插入时设置, updated_at字段在更新时自动更新。

Docs are here 文件在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM