MYSQL触发器的问题,一直报错,说代码有问题,麻烦各位帮忙看下哪错了
我水平有限看不出错在哪,求帮忙,作业啊createtriggerq0onuserafterinsert,update,deleteasbeginDECLARE@inser...
我水平有限看不出错在哪,求帮忙,作业啊
create trigger q0 on user
after insert,update,delete
as
begin
DECLARE @inserted int
declare @deleted int
select @inserted=COUNT(*) from inserted
select @deleted=COUNT(*) from deleted
if @inserted>0 and @deleted=0
begin
insert into friend(uId) select userId from inserted
end
else if @inserted>0 and @deleted>0
begin
DELETE FROM friend WHERE uId= (SELECT userId FROM DELETED)
insert into friend(uId) select userId from INSERTED
end
else if @inserted=0 and @deleted>0
begin
delete from friend
where uId=(select userId from deleted)
end
end
go
MYSQL运行一直说第一行报错 展开
create trigger q0 on user
after insert,update,delete
as
begin
DECLARE @inserted int
declare @deleted int
select @inserted=COUNT(*) from inserted
select @deleted=COUNT(*) from deleted
if @inserted>0 and @deleted=0
begin
insert into friend(uId) select userId from inserted
end
else if @inserted>0 and @deleted>0
begin
DELETE FROM friend WHERE uId= (SELECT userId FROM DELETED)
insert into friend(uId) select userId from INSERTED
end
else if @inserted=0 and @deleted>0
begin
delete from friend
where uId=(select userId from deleted)
end
end
go
MYSQL运行一直说第一行报错 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询