create trigger delete_A
on 表A for delete
as
if(select count(*) from deleted)>0
delete from 表B where coname = (select coname from deleted)
我要删除A新闻同时删除相关多个评论表B
B表超过2条信息时
出错如下
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
请教如何解决
create trigger delete_A
on 表A for delete
as
if(select count(*) from deleted)>0
delete from 表B where coname = (select coname from deleted)
我要删除A新闻同时删除相关多个评论表B
B表超过2条信息时
出错如下
子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
请教如何解决
你的表没设计好吧,级联更新,删除
新闻表字段(new_id ,new_name) new_id(primary key)为主键
评论表(p_id new_id p_text) p_id(primary key)为主键,new_id(foreign key references on update cascade on delete cascade)为外键
这样就是级联更新,级联删除,你删了含有主键的主表的记录,他的外键表记录也会相应删除
知道了吗,记得给分啊
where coname = (select coname from deleted)
改成 where coname in (select coname from deleted)