mysql - sql 语句修改一个字段,它的时间字段就跟着变
黄舟
黄舟 2017-04-17 12:03:20
0
4
583

如题
比如 a表是这样的

name number time
哈哈 23 2015-04-02 17:32:08
嘻嘻 44
呵呵 56 2015-04-16 17:32:08

用sql 语句要达到的效果是修改name字段的同时将time字段更新到当前时间 求大神指教

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
小葫芦

update a set name="123", time=now()

Or directly set the time field to automatically update

洪涛

You can use trigger. Set the trigger for the name field update event.
create trigger update_time after update on a for each row set new.time=now();

阿神

time field type is set to timestamp current_timestamp

巴扎黑

Another method is to use ON UPDATE CURRENT_TIMESTAMP

in this field when creating the table

If the database does not provide this function, you can use trigger as @drla said

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!