duanguangsong2380 2011-09-03 04:07
浏览 20
已采纳

更新应用程序或数据库中的时间戳列?

I have date_created and date_modified columns on each table in database.

What are advantages/disadvantages setting timestamp columns at database using MySQL triggers vs setting them at application layer using PHP?

Which is easier to maintain and have better time synchronization when deployed across on many servers?

EDIT: since Johan suggested setting timestamps in database is good, are these correct implementations? additionally, is it good practice to have date_created and date_modified on every table? or do you recommend adding them on certain tables?

date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
date_modified TIMESTAMP NOT NULL DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP
  • 写回答

3条回答 默认 最新

  • doucheng3407 2011-09-03 04:11
    关注

    Timestamp in the database.

    If you replicate in a master-slave setup, database timestamps are correctly replicated (using the original timestamp).

    You do not (!) set timestamps in triggers.

    Instead you specify them in the table definition, MySQL will automatically set the correct timestamp on insert and/or update.
    You only have to set them once, when you create (or alter) the table and that's it.

    Could not be easier.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案