create trigger portGo
after insert on wc
for each row
begin
select count(*) into @num from dataIn where port = new.name;
if @num=0 then
insert into dataIn values ('4',new.name);
end if;
end$

是这样的,在做海运报价查询系统里,所有的港口,要重新统计整理嘛,故使用触发器来实现吧。

wc表是用来插入海运数据的。

dataIn表是原对照的port.

当有导入数据时,若是新港口,刚自动更新到dataIn中。

create trigger portAutoAdd
after insert on seaend 
for each row  
begin  
select count(id) into @num from seaport where shortName = new.endP;  
if @num=0 then  
insert into seaport (shortName) values (new.endP);  
end if;  
end$