본문 바로가기

linux/mysql

[Mysql] 날짜/시간 자동입력

php에서 함수로 찍어주는것보다 now()라는 mysql자체함수가 훨씬 효과적인것 같습니다 ^^ 
CREATE TABLE example_default_now (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
data VARCHAR(100),
created TIMESTAMP DEFAULT NOW()
);


insert into example_default_now values(default,'test1',default);
insert into example_default_now values(default,'test1',default);

mysql> select * from example_default_now;
+----+-------+---------------------+
| id | data | created |
+----+-------+---------------------+
| 1 | test1 | 2009-10-10 18:12:56 |
| 2 | test1 | 2009-10-10 18:13:14 |
+----+-------+---------------------+
2 rows in set (0.00 sec)