鉴于此表
mysql> describe last_user_activity;
+--------------+------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------+------+-----+-------------------+-------+
| customer_id | int(11) | NO | | NULL | |
| token | text | NO | | NULL | |
| time_stamp | timestamp | YES | | CURRENT_TIMESTAMP | |
| is_logged_in | tinyint(1) | NO | | 0 | |
+--------------+------------+------+-----+-------------------+-------+
4 rows in set (0.00 sec)
我想“触摸”表格的一行,将 time_stamp
设置为其默认值 CURRENT_TIMESTAMP
。
我想我可以尝试
UPDATE last_user_activity WHERE token="40aed4d9-c9ac-471e-8d53-b2baa0d72523";
(这是表中的有效标记),但这导致了
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE token="40aed4d9-c9ac-471e-8d53-b2baa0d72523"' at line 1
哦,好吧,这看起来很聪明,但是 NVM。所以,然后我尝试了
UPDATE last_user_activity SET token="40aed4d9-c9ac-471e-8d53-b2baa0d72523"
WHERE token="40aed4d9-c9ac-471e-8d53-b2baa0d72523";
表示成功,但是,时间戳字段未更新。
我做错了什么?
最佳答案
UPDATE last_user_activity
SET time_stamp = NULL
WHERE token="40aed4d9-c9ac-471e-8d53-b2baa0d72523";
或者
UPDATE last_user_activity
SET time_stamp = NOW()
WHERE token="40aed4d9-c9ac-471e-8d53-b2baa0d72523";
关于mysql - 仅更新 MySql 表中的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40240026/