mysql外键级联删除子表并让子表触发触发器 10

MYSQL外键级联删除子表并让子表触发触发器tableA:field:a_idPRItable:Bfield:b_idPRIb_comment并在用tableB中ALTE... MYSQL外键级联删除子表并让子表触发触发器
table A :
field:a_id PRI
table:B
field: b_id PRI

b_comment
并在用table B中
ALTER TABLE B

ADD CONSTRAINT `fx`
FOREIGN KEY (`b_id` )
REFERENCES A (`a_id` )
ON DELETE CASCADE
ON UPDATE NO ACTION;

DELIMITER $$
CREATE TRIGGER `del_b`
AFTER DELETE ON b
FOR EACH ROW
begin
set @x=852369;
end$$
insert into A(a_id)values(1);
insert into B(b_id,b_comment) values(1,2);
delete from B where b_id = 1;
select @x;
显示@x = NULL
不好意思上面那句删除的delete from B where b_id = 1;写错了 修改成 delete from A;
但是最后面怎么就显示@x=NULL, 不是@x的值应该是852369的吗
展开
 我来答
playsenlin
2012-09-25 · TA获得超过101个赞
知道小有建树答主
回答量:438
采纳率:0%
帮助的人:237万
展开全部
/**********************************************/
/*触发器:删除岗位时删除 岗位考试 能力项 **********/
/********************************************/
drop trigger del_Position_all
go
create trigger del_Position_all
on t_Position
for delete
as
declare @a char(10)
declare @guid char(40)
select @a=po_id,@guid=po_ca_guid from deleted
delete from t_PositionToCourse where pc_po_id=@a and pc_ca_guid=@guid /*删除岗位与课程对应关系*/
delete from t_spreadword where sw_st_id in(select st_id from t_spreadType where st_s_id in (select s_id from t_spread where s_po_id=@a and s_ca_guid=@guid))--先删除文档
delete from t_spreadType where st_s_id in (select s_id from t_spread where s_po_id=@a and s_ca_guid=@guid)--删步聚
delete from t_spread where s_po_id=@a and s_ca_guid=@guid --删传承
go
不要用外键。还在用!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式