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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?