sql server - Delete multiple rows by sql statement "delete from tableName" whereas TRIGGER "After Delete" had applied on that -


i have applied "after delete" trigger on 1 table, below script:

alter trigger [dbo].[ondelete_n_ur]    on  [dbo].[notification_unread]    after delete  begin   set nocount on;  declare @roid int  set @roid=(select reachoutid deleted(nolock)   deleted.notificaiontype='reachoutlike')   update cache_reachout  set cache_reachout.likecount=(select [dbo].[getreachout_notification_count](@roid,'like') )  cache_reachout.reachoutid=@roid 

end

now trying delete rows in bulk using following sql statement:

delete  notification_unread notification_id=**** 

and it's giving me error

subquery returned more 1 value. not permitted when subquery follows =, !=, <, <= , >, >= or when subquery used expression." 

how can delete multiple rows using above delete statement when delete trigger applied on .

try 1 -

alter trigger [dbo].[ondelete_n_ur]   on [dbo].[notification_unread]   after delete begin        set nocount on;       declare @roid int      set @roid =      (           select top 1 reachoutid           deleted d           d.notificaiontype = 'reachoutlike'      )        update cache_reachout      set cache_reachout.likecount = dbo.getreachout_notification_count(@roid, 'like')      cache_reachout.reachoutid = @roid  end 

or try (more preferably using) -

alter trigger [dbo].[ondelete_n_ur]   on [dbo].[notification_unread]   after delete begin       set nocount on;       update t      set likecount = dbo.getreachout_notification_count(d.reachoutid, 'like')      cache_reachout t      join deleted d on t.reachoutid = d.reachoutid      d.notificaiontype = 'reachoutlike'  end 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -