在数据库操作中常需要delete,insert,update数据库表,在一个表发生变化时,其他表可以做相应的变化,下面就写下,今天研究了一天的Linux下触发器的知识:delete -- > old
insert -- > new
update -- > old & new
1 tbl_AreaInfo
删除触发器
CREATE TRIGGER tr_ai_delete BEFORE Delete ON tbl_AreaInfo
FOR EACH ROW
delete from tbl_DataRight where tbl_DataRight.dr_AreaId=OLD.ai_Id
2 tbl_DeviceInfo
删除触发器
delimiter //
CREATE TRIGGER tr_di_delete BEFORE Delete ON tbl_DeviceInfo
FOR EACH ROW
BEGIN
delete from tbl_AlarmSubscribe where tbl_AlarmSubscribe.as_DeviceId=OLD.di_Id;
delete from tbl_CameraInfo where tbl_CameraInfo.ci_DeviceId=OLD.di_Id;
delete from tbl_FailureHistory where tbl_FailureHistory.fh_DeviceId=OLD.di_Id;
delete from tbl_AlarmInput where tbl_AlarmInput.ai_DeviceId=OLD.di_Id;
END;//
3 tbl_FailureHistory
删除触发器
CREATE TRIGGER tr_fh_delete BEFORE Delete ON tbl_FailureHistory
FOR EACH ROW
delete from tbl_ProcessHistory where tbl_ProcessHistory.ph_FailureHistoryId=OLD.fh_Id
插入触发器
delimiter //
CREATE trigger tr_fh_insert BEFORE Insert on tbl_FailureHistory
FOR EACH ROW
BEGIN
insert into tbl_ProcessHistory set ph_FailureHistoryId=new.fh_Id,
ph_ProcessStatusId=new.fh_ProcessStatusId,
ph_CreaterId=new.fh_ProcesserId,
ph_CreateTime=new.fh_ProcessTime,
ph_Memo=new.fh_ProcessMemo;
END;//
更新触发器
delimiter //
CREATE trigger tr_fh_update BEFORE Update on tbl_FailureHistory
FOR EACH ROW
BEGIN
if (old.flag = 1,new.flag = 1) then
insert into tbl_ProcessHistory set ph_FailureHistoryId=new.fh_Id,
ph_ProcessStatusId=new.fh_ProcessStatusId,
ph_CreaterId=new.fh_ProcesserId,
ph_CreateTime=new.fh_ProcessTime,
ph_Memo=new. fh_ProcessMemo;
end if;
if (old.flag = 1,new.flag = 0) then
update tbl_ProcessHistory set tbl_ProcessHistory.flag=0 where tbl_ProcessHistory.ph_FailureHistoryId=new.fh_Id;
end if;
if (old.flag = 0,new.flag = 1) then
update tbl_ProcessHistory set tbl_ProcessHistory.flag=1 where tbl_ProcessHistory.ph_FailureHistoryId=new.fh_Id;
End if;
END;//在Fedora下安装Oracle 10gR2 及 Oracle 11g 摘记Linux AS 4上升级Oracle 10.2.0.1.0到10.2.0.4.0的过程相关资讯 mysql Linux教程
- Linux教程:如何在命令行中查看目 (07/28/2014 12:22:23)
- MySQL Administrator连接VMWare下 (05/24/2013 09:20:58)
- MySQL 5.1.68 发布 (02/05/2013 08:37:47)
| - 数据库服务器 MySQL (08/15/2013 06:50:23)
- MySQL 5.6 GA 及逃亡潮 (02/08/2013 14:36:35)
- Linux进程间通信:消息队列 (01/28/2013 09:43:00)
|
本文评论 查看全部评论 (0)