문제

I am trying the following SQL statement:

create table sample (
id int not null primary key auto_increment,
name varchar(100),
date_modified timestamp not null default current_timestamp on update current_timestamp,
date_created timestamp not null default now()
)

It's not working... I'm getting the following error:

#1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

I need to keep track of two date stamps, one for the date the row was created and one for the date the row was last modified. They both do what I want I use them alone, but MySQL will not allow me to combine them in a single table.

Please help. :)

도움이 되었습니까?

해결책

You can create trigger BEFORE UPDATE and modify date_modified in it.

Or BEFORE INSERT and create date_created there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top