Web Applicationを作成していてデータが入力された時間を
保存しておきたいという事が多々あります。
MS SQLでは時間列のDefault値として(getdate())を設定しますが
MY SQLではCURRENT_TIMESTAMPを利用します。

(例)


mysql> CREATE TABLE `BBS` (
-> `comment` varchar(100) NULL DEFAULT NULL,
-> `comment_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP
-> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> desc BBS;
+--------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+-------------------+-------+
| comment | varchar(100) | YES | | NULL | |
| comment_time | timestamp | YES | | CURRENT_TIMESTAMP | |
+--------------+--------------+------+-----+-------------------+-------+
2 rows in set (0.00 sec)

mysql> insert into BBS(comment) values('Hello World!');
Query OK, 1 row affected (0.00 sec)

mysql> select * from BBS;
+--------------+---------------------+
| comment | comment_time |
+--------------+---------------------+
| Hello World! | 2009-07-09 12:26:23 |
+--------------+---------------------+
1 row in set (0.01 sec)

mysql>

bbs

Comments are closed.

Post Navigation