简体   繁体   English

使用时间戳手动跟踪更改还是自动跟踪更改?

[英]Tracking changes manual using timestamps or automatic?

I have two databases synchronized using tracking changes of SqlServer 2008 Tracking Changes and it's cool because without effort I can control the inserts/updates and deletes of a database and send to the other. 我有两个使用SqlServer 2008 Tracking Changes的跟踪更改同步的数据库,这很酷,因为我可以毫不费力地控制数据库的插入/更新和删除,然后发送给另一个数据库。 Currently I'm migrating the system to MySQL. 目前,我正在将系统迁移到MySQL。 Does exists something similar to track changes or I have to implement it manually. 是否存在类似于跟踪更改的内容,或者我必须手动实现它。

To implement this manually is a good approach use a timestamp to control INSERTS/UPDATES and triggers to fill a deletions table to control DELETES? 要手动执行此操作是一种好方法,请使用时间戳记来控制插入/更新,并触发填充删除表来控制DELETES?

When I say timestamp I want to say SQLServer timestamp (binary field that automatically increments when the register is inserted, modified. Does exists something similar to SQLServer timestamp in MySQL? 当我说时间戳时,我想说的是SQLServer时间戳(二进制字段,在插入寄存器时会自动增加,修改。在MySQL中是否存在类似于SQLServer时间戳的内容?

Thanks 谢谢

Yes, you can monitor changes in a table (INSERTs, UPDATEs) using MySQL TIMESTAMP field; 是的,您可以使用MySQL TIMESTAMP字段监视表中的更改(INSERT,UPDATE); the TIMESTAMP field has to be created with ON UPDATE CURRENT_TIMESTAMP option. TIMESTAMP字段必须使用ON UPDATE CURRENT_TIMESTAMP选项创建。 It will help you to know when the record was changed. 它会帮助您知道记录何时更改。

For example - 例如 -

CREATE TABLE table1(
  id INT(11) NOT NULL,
  name VARCHAR(255) DEFAULT NULL,
  ts TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
);

More information here - Automatic Initialization and Updating for TIMESTAMP . 此处的更多信息-TIMESTAMP的自动初始化和更新

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

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