我想用date好工作台初始化表中的默认CURRENT_DATE();字段,这给了我不可能听到的触发器错误,但是对于这个问题,似乎有点过于复杂了,所以有没有办法这样做呢?
CREATE TABLE Sprzedaz (
Id int unsigned primary key auto_increment,
KlientId int not null,
ProduktNumer int not null,
Ilosc int not null,
Cena float not null,
Data date default CURRENT_DATE(),
check (Data >= now()),
....
);发布于 2013-11-21 21:06:18
可以使用以下内容初始化时间戳列:
Data TIMESTAMP DEFAULT CURRENT_TIMESTAMP或日期时间列(MySQL 5.6+):
Data DATETIME DEFAULT CURRENT_TIMESTAMP但是,如果要使用MySQL 5.5初始化日期列,则需要插入触发器:
CREATE TRIGGER setdate_before_insert BEFORE INSERT ON test
FOR EACH ROW
SET NEW.Data = CURDATE();也许你还需要一个更新触发器?请看小提琴这里。
发布于 2013-11-21 21:03:44
如果您不介意更改date类型,那么另一种方法是使用TIMESTAMP并使用TIMESTAMP DEFAULT CURRENT_TIMESTAMP初始化它。然后,你的定义将变成:
CREATE TABLE Sprzedaz (
Id int unsigned primary key auto_increment,
KlientId int not null,
ProduktNumer int not null,
Ilosc int not null,
Cena float not null,
Data TIMESTAMP DEFAULT CURRENT_TIMESTAMP, <<<==== change this
check (Data >= now()),
....
);发布于 2013-11-21 21:04:04
如果您有MySQL版本5.6.5及以上版本,您可以使用CURRENT_TIMESTAMP而不是CURRENT_DATE
请参阅http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html
所以你不能用日期来做这件事,但是你可能会改变你的领域,成为一个时间戳或约会时间,而你的母亲,兄弟!
https://stackoverflow.com/questions/20131591
复制相似问题