IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_report_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_report_delete]
GO
--报表类别删除触发器
CREATE trigger [dbo].[mps_report_delete] on [dbo].[mps_report] for delete as
begin
   delete mps_report_users  from deleted where  rptp_rptid=rpt_id 
insert into mps_sync(sk_type,sk_bizid,sk_objid,sk_operation,sk_tag2) 
select 23 , rpt_id , rpt_id , -1 , 0 from deleted 
   
   declare @cmpid int 
   declare @sql nvarchar(2000) 
   declare status1 cursor LOCAL FORWARD_ONLY READ_ONLY for
  select rpt_cmpid,rpt_id  from   deleted
  open status1
  declare @ord2tag int 
  FETCH NEXT FROM status1 INTO @cmpid,@ord2tag 
  WHILE (@@FETCH_STATUS = 0)
  BEGIN

--检查存储过程是否存在,如果存在则删除存储过程
   set @sql = 'report_'+rtrim(ltrim(str(@ord2tag)))+'_data'
   if (dbo.checkprocedure(@sql)=0) 
   begin
   set @sql = N'drop procedure '+@sql 
exec(@sql)
end 
   FETCH NEXT FROM status1 INTO @cmpid,@ord2tag 
  END
  CLOSE status1
DEALLOCATE status1 
--删除报表模板
delete from mps_template where tmp_type in ('rptdisp','rpt','rpt_c','rpt_sc')
and tmp_objid not in(select rpt_id from mps_report)
end