我的数据库是MySQL 5.1,我现在有一个产品表product,同时还有一个产品点击表phits,我要实现我往product插入一条记录,系统就会自动触发这个存储过程生存一个phits表插入事件,插入到phits表的ID字段,这个字段的值就是产品表的ID字段的值(product.ID),生存的phits表记录,结构是ID,hits,shits,dhits,只有ID是有值的,其他默认0
phits表有设外键关联product表
phits表有设外键关联product表
after insert
on product for each row
begin
insert into phits values(new.id,new.hits,new.shits,new.dbits);
end
create trigger tri_test
after insert
on product for each row
begin
insert into phits(ID) select max(ID) from product;
end insert into phits(ID) select max(ID) from product;有没有更好的解决方法呢?select max(ID) from product有没有更高效率的语句,,可以解决inserted