喜的IM试图创建该表的触发器:触发问题与语法
create table Episode(
title varchar(25) not null,
number int not null,
length time not null,
aired date not null,
serie_name varchar(25),
PRIMARY KEY(title,number),
FOREIGN KEY (serie_name)REFERENCES Serie(name)
) ENGINE=InnoDB;
这是保存一些电视系列DB表...所以触发器必须检查IM试图插入一个在先例之前已经播出的新剧集......但是我遇到了一些问题吗? 我试过这个:
create trigger ControlDataEp
before insert on Episode
for each row
begin
if new.aired<(select aired from Episode where title=new.title and number=new.number-1)
then raise.application_error(-21,'error');
end if;
end;
啊确定它那真棒,但是是我第一次看到
Skyzzo
@Skyzzo ** ['NEW'](http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html)**是一个别名,它允许您引用正在插入(或更新)的行。 'NEW.aired'和'NULL'是** ['IF()'](http://dev.mysql.com/doc/refman/5.5/en/control-flow-functions)的第二和第三个参数。 html#function_if)**函数。它允许检查条件,如果它是真的返回正在插入的值(NEW.aired),并且它返回NULL,则违反约束条件。 – peterm