MySQL 데이터 형식 timestamp에 대한 토론

4758 단어 Timestamp
프로젝트에timestamp 형식을 사용했습니다. 이 필드는 줄 바꿈 기록의 생성 시간을 저장하는 데 사용되며, 실제로는 매우 위험한 설정입니다.
mysql 공식 문서에는 다음과 같은 구절이 있습니다.
The  TIMESTAMP  data type provides a type that you can use to automatically mark  INSERT  or  UPDATE  operations with the current date and time. If you have multiple  TIMESTAMP  columns in a table, only the first one is updated automatically. (From MySQL 4.1.2 on, you can specify which  TIMESTAMP  column updates;
시간stamp 형식은 insert나 업데이트 업데이트에 따라 자동으로 업데이트된다는 뜻입니다.
다음은 실제로 하나의 사례를 테스트해 보겠습니다.
mysql> create table b(ID int ,Time timestamp);Query OK, 0 rows affected (0.01 sec)
mysql> insert into b values(1,now());Query OK, 1 row affected (0.00 sec)
mysql> insert into b values(2,now());Query OK, 1 row affected (0.01 sec)
-------------------------------------------------
mysql> select * from b;+------+---------------------+| ID   | Time                |+------+---------------------+|    1 | 2013-07-26 13:56:11 ||    2 | 2013-07-26 13:57:43 |+------+---------------------+
------------------------------------------------
mysql> update b  set  id=3 where id=2;
------------------------------------------------
mysql> select * from b;+------+---------------------+| ID   | Time                |+------+---------------------+|    1 | 2013-07-26 13:56:11 ||    3 | 2013-07-26 16:35:43 |+------+---------------------+
 
타임스탬프가 자동으로 업데이트되었음을 알 수 있습니다.더 많은timestamp 정보는 mysql 공식 문서를 볼 수 있습니다http://dev.mysql.com/doc/refman/4.1/en/timestamp-pre-4-1.html
 
 

좋은 웹페이지 즐겨찾기