oracle触发器实现级联删除
老师要求用触发器,删除联系人表中的一行,把残疾人,老年人表中与联系人表要删除的那一行身份证号相符的一起删除,但是是先删老年人表,但是这些表中未必有那一行身份证号相符的我写...
老师要求用触发器,删除联系人表中的一行,把残疾人,老年人表中与联系人表要删除的那一行身份证号相符的一起删除,但是是先删老年人表,但是这些表中未必有那一行身份证号相符的
我写的编译通过但是报警了,且后期试了不好使,该怎么写?
create or replace trigger naomi.delete_contacts
before delete on CONTACTS
for each row
begin
delete from Elderly where people_id = :old.people_id;
delete from Soldier where people_id = :old.people_id;
delete from disabled where people_id = :old.people_id;
delete from student where people_id = :old.people_id;
end; 展开
我写的编译通过但是报警了,且后期试了不好使,该怎么写?
create or replace trigger naomi.delete_contacts
before delete on CONTACTS
for each row
begin
delete from Elderly where people_id = :old.people_id;
delete from Soldier where people_id = :old.people_id;
delete from disabled where people_id = :old.people_id;
delete from student where people_id = :old.people_id;
end; 展开
1个回答
展开全部
使用级联删除+触发器可以搞定你的需求。\r\n父表A 子表B 备份表C\r\n命令如下:\r\ncreate table A \r\n(\r\n dept_ID number primary key,\r\n dept_name varchar2(10)\r\n);\r\n\r\ncreate table B\r\n(\r\n no number primary key,\r\n name varchar2(10),\r\n dept_id number\r\n);\r\n\r\nALTER TABLE WWJ.B ADD CONSTRAINT FK_B FOREIGN KEY (DEPT_ID) REFERENCES WWJ.A (DEPT_ID) ON DELETE CASCADE ENABLE VALIDATE;\r\n\r\nCREATE OR REPLACE TRIGGER WWJ.TR_B_01\r\nBEFORE DELETE\r\nON WWJ.B \r\nREFERENCING NEW AS New OLD AS Old\r\nFOR EACH ROW\r\nBEGIN\r\n INSERT INTO C VALUES(:old.no,:old.name,:old.dept_id);\r\nEND;
TableDI
2024-07-18 广告
2024-07-18 广告
`VLOOKUP` 匹配出错误的数据通常是由于以下几个原因:1. **查找值错误**:输入的查找值与数据源中的值不匹配,可能是因为拼写错误、大小写不一致或存在不可见的字符。2. **查找区域设置错误**:查找区域的首列必须包含要查找的值,且...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询