如何将张三的时间改为系统时间?
这个容易,看我给你的代码
> CREATE TABLE `test` (
-> `id` int NOT NULL,
-> `name` varchar(255),
-> `update_time` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-> PRIMARY KEY (`id`)
-> ) COMMENT='测试';
MariaDB [test]> insert into test (id,name) values(1,'demo');
Query OK, 1 row affected (0.01 sec)
MariaDB [test]> select * from test;
+----+------+---------------------+
| id | name | update_time |
+----+------+---------------------+
| 1 | demo | 2017-05-19 14:10:20 |
+----+------+---------------------+
1 row in set (0.00 sec)
MariaDB [test]> update test set name='zhangsan' where id=1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [test]> select * from test;
+----+----------+---------------------+
| id | name | update_time |
+----+----------+---------------------+
| 1 | zhangsan | 2017-05-19 14:10:40 |
+----+----------+---------------------+
1 row in set (0.00 sec)
1.字段类型为时间戳 timestamp
2.默认值为CURRENT_TIMESTAMP
3.如果需要更新该条记录时,自动更新时间,那就加上 ON UPDATE CURRENT_TIMESTAMP
5 回答3.3k 阅读✓ 已解决
3 回答3.6k 阅读✓ 已解决
1 回答4.1k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
2 回答2.3k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
5 回答1.4k 阅读
update stu set stuDate = now() where stuName = '张三';