TIMESTAMP存储在MySQL专有方法中(尽管它基本上只是一个由年,月,日,小时,分钟和秒组成的字符串),此外,每当插入或更改记录时,TIMESTAMP类型的字段都会自动更新.字段值给出:
mysql> create table timestamp_test(
id integer not null auto_increment primary key,
val varchar(100) not null default '', ts timestamp not null);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into timestamp_test (val) values ('foobar');
Query OK, 1 row affected (0.00 sec)
mysql> select * from timestamp_test;
+----+--------+----------------+
| id | val | ts |
+----+--------+----------------+
| 1 | foobar | 20090122174108 |
+----+--------+----------------+
1 row in set (0.00 sec)
mysql> update timestamp_test set val = 'foo bar' where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from timestamp_test;
+----+---------+----------------+
| id | val | ts |
+----+---------+----------------+
| 1 | foo bar | 20090122174123 |
+----+---------+----------------+
1 row in set (0.00 sec)
mysql>
Run Code Online (Sandbox Code Playgroud)DATETIME是日期和时间的标准数据类型,它与MySQL中的日期和时间函数一起使用.我可能在实践中使用它
| 归档时间: |
|
| 查看次数: |
1168 次 |
| 最近记录: |