MySQL时间戳仅在创建时 [英] MySQL timestamp only on create

查看:90
本文介绍了MySQL时间戳仅在创建时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL 5.x(带有PHP)上使用时间戳记来记住事件时间.在开发过程中,我不得不使用查询来更新表,该查询会更改所有列中的内容.然后将时间戳重置为当前时间.

I use timestamp on MySQL 5.x (with PHP) to remember event times. During development I had to update the table with a query that changes something in all columns. The timestamp was then reset to current time.

如何仅在插入时更改时间戳,而不能在更新或替换时更改时间戳?

How can I make timestamp change only on inserts and not on updates or replace?

推荐答案

Here's all you need to know. In short, though, I think this should do it:

ALTER TABLE `mytable`
CHANGE `mydatefield` `mydatefield`
TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

这篇关于MySQL时间戳仅在创建时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆