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
'MySQL' 카테고리의 다른 글
32. MySQL Subquery (서브쿼리) 사용법 / select문 안에 select문 넣기 (0) | 2021.07.27 |
---|---|
31. MySQL tinyint(1) vs tinyint(4) 차이 (0) | 2021.07.25 |
29. MySQL 트랜잭션(START TRANSACTION) (0) | 2021.07.23 |
28. MySQL AUTO_INCREMENT 값 초기화 (0) | 2021.07.20 |
27. MySQL int(11) 그리고 ZEROFILL (0) | 2021.07.19 |