加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php – ‘创建于’和’更新在’字段

发布时间:2020-05-25 09:55:38 所属栏目:PHP 来源:互联网
导读:这似乎是一个非常简单的一个,但我很难想出来.我想要一个列在我的数据库中列出了创建一个记录,另一列说明何时更新.这是我的理解,我应该能够使用所有这一切只使用 MySQL.所有的帮助是赞赏:) 这个臭味还没有回答,原因我已经开始错过Ruby on Rails … 您可能需要

这似乎是一个非常简单的一个,但我很难想出来.我想要一个列在我的数据库中列出了创建一个记录,另一列说明何时更新.这是我的理解,我应该能够使用所有这一切只使用 MySQL.所有的帮助是赞赏:)

这个臭味还没有回答,原因我已经开始错过Ruby on Rails …

您可能需要使用Datetime数据类型和Timestamp数据类型的组合.我将使用DEFAULT NOW()将我创建的列设置为DateTime,将已更新的列设置为具有DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP属性的Timestamp.

以下是Timestamp dt的文档:

http://dev.mysql.com/doc/refman/5.0/en/timestamp.html

In a CREATE TABLE statement,the first TIMESTAMP column can be declared in any of the following ways:

With both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses,the column has the current timestamp for its default value,and is automatically updated.

With neither DEFAULT nor ON UPDATE clauses,it is the same as DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.

With a DEFAULT CURRENT_TIMESTAMP clause and no ON UPDATE clause,the column has the current timestamp for its default value but is not automatically updated.

With no DEFAULT clause and with an ON UPDATE CURRENT_TIMESTAMP clause,the column has a default of 0 and is automatically updated.

With a constant DEFAULT value,the column has the given default and is not automatically initialized to the current timestamp. If the column also has an ON UPDATE CURRENT_TIMESTAMP clause,it is automatically updated; otherwise,it has a constant default and is not automatically updated.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读