본문 바로가기

DB/Mysql

Mysql timestamp update null value, mysql에서 timestamp 컬럼에 null을 update할때


Mysql에서 자주 사용하는 TimeStamp는 날짜, 혹은 시간을 나타내는 컬럼이다. 

Mysql의 Tiemstamp관련 문서다. 
http://dev.mysql.com/doc/refman/5.0/en/timestamp.html


TIMESTAMP columns are NOT NULL by default, cannot contain NULL values, and assigning NULL assigns the current timestamp. However, a TIMESTAMP column can be permitted to contain NULL by declaring it with the NULL attribute. In this case, the default value also becomes NULL unless overridden with a DEFAULT clause that specifies a different default value. DEFAULT NULL can be used to explicitly specify NULL as the default value. (For a TIMESTAMP column not declared with the NULL attribute, DEFAULT NULL is illegal.) If a TIMESTAMP column permits NULL values, assigning NULL sets it to NULL, not to the current timestamp.


위에서 읽어 볼 수 있는데 TIMESTAMP의 기본 설정이 NOT NULL이고 NULL 값을 할당(assign)하면 current timestamp(현재 시간)이 update된다. 
개념없어 몰랐던 내용인데 혹시 궁금한 사람이 있을까 해서 적어 놓는다.