日期:2014-05-18  浏览次数:20562 次

关于触发删除的确问题在于
我想有一张表,里面有一项关联到三张表,我想删除主表中的一项然后出发删除这三张表中的一张表的记录
ALTER   TRIGGER   Delete_NodeRelation   ON     NodeRelation  
FOR   DELETE  
AS
if   deleted.Type   =   1  
                    delete   Area   from   Area,deleted   where   Area.AreaID   =   deleted.NodeRelationID
else   if  
                    deleted.type   =   2   delete   SpotInfo   from   SpotInfon,deleted   where   SpotInfo.SpotID   =   deleted.NodeRelationID
else
-- delete   ChannelInfo   from   ChannelInfo,deleted   where   ChannelInfo.channelID   =   deleted.NodeRelationID

可是这样子老是提示第一行的deleted.type有错误,请问该怎么解决


------解决方案--------------------
yrwx001() ( ) 信誉:100 Blog 加为好友 2007-07-16 09:33:26 得分: 0


ALTER TRIGGER Delete_NodeRelation ON NodeRelation
FOR DELETE
AS
declare @Type int
select @Type = Type from deleted --这样只能处理deleted表的一条,如果多条的话会有问题
if @Type = 1
delete Area from Area,deleted where Area.AreaID = deleted.NodeRelationID
else if @Type = 2
delete SpotInfo from SpotInfon,deleted where SpotInfo.SpotID = deleted.NodeRelationID
else
-- delete ChannelInfo from ChannelInfo,deleted where ChannelInfo.channelID = deleted.NodeRelationID