0

我正在尝试以下 SQL 语句:

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()
)

它不起作用...我收到以下错误:

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

我需要跟踪两个日期戳,一个用于创建该行的日期,一个用于该行的最后修改日期。他们都做我想做的事,我单独使用它们,但 MySQL 不允许我将它们组合在一个表中。

请帮忙。:)

4

1 回答 1

0

您可以在其中创建触发器BEFORE UPDATE并进行修改date_modified

或者在那里BEFORE INSERT创建date_created

于 2010-12-22T01:25:34.140 回答