create or replace trigger tri_table_A
after delete on table_A
for each row
begin
delete from table_b where b.id=:old.id
end tri_table_A
/
触发器顾名思意就是在某个动作执行时自动触发执行的,不用调用,比如你是在add和delete数据时加触发器,只要你定义的对,数据库在向你指定的那张表add和delete数据时,该触发器就会自动触发2.在Java程序里创建触发器String sql=+" CREATE TRIGGER catefiles_trigger AFTER INSERT ON catefiles FOR EACH ROW"
+" begin"
+" declare scannum int"
+" set scannum = (select num from est_client_catescan_status where"
+" cateid=new.cateId and taskid=new.taskId and clientid=new.clientId)"
+" if(scannum>=0) then"
+" update catescan_status set num=scannum+1 where cateid=new.cateId and taskid=new.taskId and clientid=new.clientId"
+" else"
+" insert catescan_status(cateid,num,status,taskid,clientid) values(new.cateId,1,0,new.taskid,new.clientId)"
+" end if"
+" end"
Connection con = DbConnectionManager.getConnection()
PreparedStatement pstmt = con.prepareStatement(sql)
pstmt.execute()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)