MySQL
30. MySQL 날짜컬럼 변경시 자동으로 업데이트 되게 하기
drizzle0925
2021. 7. 23. 15:50
728x90
ON UPDATE CURRENT_TIMESTAMP
구문 예제
CREATE TABLE `fruit` (
id int(11) unsigned not null primary key auto_increment,
name varchar(30) not null,
amount int(11) unsigned not null default 0,
created_at timestamp not null default current_timestamp,
updated_at timestamp not null default current_timestamp on update current_timestamp
);
default는 기본값으로 current_timestamp 현재 시간을 입력하고 뒤에 on update current_timestamp라고 입력해서 갱신이 생겼을 경우 updated_at 칼럼의 시간을 변경시킨다.
728x90