Question

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. :)

Was it helpful?

Solution

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

Or BEFORE INSERT and create date_created there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top