mysql中有一个“注册时间”字段,datetime类型,约束为not null。
我希望再设一个默认值为当前时间。
网上找了很多,都说要转成timestamp类型。
但timestamp类型好象只要修改了该条字段的内容就会自动更改为当前时间(是不是我的理解有错)。
那注册时间肯定不能发生改变呀,请问怎么办?
第一次来,望好心人解答
我希望再设一个默认值为当前时间。
网上找了很多,都说要转成timestamp类型。
但timestamp类型好象只要修改了该条字段的内容就会自动更改为当前时间(是不是我的理解有错)。
那注册时间肯定不能发生改变呀,请问怎么办?
第一次来,望好心人解答
Query OK, 0 rows affected (0.11 sec)mysql> insert into testtime(id) values(1);
Query OK, 1 row affected (0.13 sec)mysql> select * from testtime;
+------+---------------------+
| id | rowdate |
+------+---------------------+
| 1 | 2011-05-22 05:20:22 |
+------+---------------------+
1 row in set (0.00 sec)mysql> update testtime set id=2;
Query OK, 1 row affected (0.13 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from testtime;
+------+---------------------+
| id | rowdate |
+------+---------------------+
| 2 | 2011-05-22 05:20:22 |
+------+---------------------+
1 row in set (0.00 sec)
我才刚刚开始接触mysql,在理解上很容易出错
我知道你们的回答很有用,但那么长的一段,实在让我看得有点晕
这样说吧
注册时间 timestamp not null default current_timestamp,
这样写注册时间对吗?在修改和取值时会不会有什么问题?
回答这个就行,不对的话还请指教
最好再告诉我用PHP怎么取出这个时间的语句,呵呵.......
;
Query OK, 0 rows affected (0.19 sec)mysql> insert into test4 (id) values(1);
Query OK, 1 row affected (0.03 sec)mysql> select * from test4;
+------+---------------------+
| id | a |
+------+---------------------+
| 1 | 2011-05-22 18:02:17 |
+------+---------------------+
1 row in set (0.00 sec)mysql> update test4 set id=id+1;
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from test4;
+------+---------------------+
| id | a |
+------+---------------------+
| 2 | 2011-05-22 18:02:17 |
+------+---------------------+
1 row in set (0.00 sec)
productArea.setLastUpdateTime(new Date());
就是 系统默认时间~~~~~~~~~