IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_del_1biztype]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_del_1biztype]
GO
CREATE  procedure [dbo].[mps_del_1biztype](  
@cmpid int ,  
@bizid int   
) as  
begin  
 --   
 declare @tbid int   
 declare @dbname varchar(50)   
 declare @tbname varchar(100)   
 declare @skeyfld varchar(50)   
   
 exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output , @skeyfld output , @dbname output   
 set @skeyfld='ord_id'   
 set @tbname = @dbname+@tbname   
    
   
 declare @sql nvarchar(3000)   
 set @sql = 'drop table '+@tbname+'_users'   
 execute(@sql)   
 declare status1 cursor LOCAL FORWARD_ONLY READ_ONLY for  
   select biz2_tag  from mps_biztype2  where biz2_bizid=@bizid   
   open status1  
   declare @ord2tag int   
   FETCH NEXT FROM status1 INTO @ord2tag   
   WHILE (@@FETCH_STATUS = 0)  
   BEGIN  
     set @sql = 'drop table '+@tbname+'_'+rtrim(ltrim(str(@ord2tag)))   
  exec(@sql)  
     FETCH NEXT FROM status1 INTO @ord2tag   
   END  
   CLOSE status1  
 DEALLOCATE status1   
 set @sql = 'drop table '+@tbname+'_0'   
 exec(@sql)  
 set @sql = 'drop table '+@tbname+'_relation'  
 exec(@sql)  
 set @sql = 'drop table '+@tbname   
 exec(@sql)  
   
 delete mps_fieldinfo_operation where fldi_tbtype='biz' and fldi_tbid=@bizid   
   
 delete mps_fieldinfo where fldi_tbtype='biz' and fldi_tbid=@bizid   
   
 delete  mps_biztype_comefrom where bs_bizid=@bizid   
 delete mps_biztype_comefrom where bs_stype='biz' and bs_sbizid=@bizid   
   
 delete  mps_biztype2 where biz2_bizid = @bizid   
   
 delete mps_biztype_source where bizs_type='biz' and bizs_bizid=@bizid   
 delete mps_biztype_source where bizs_sourcetype='biz' and bizs_ctgid=@bizid   
   
 delete mps_biztype where biz_id=@bizid   
 
delete mps_biztype_relation where  br_bizid2 = @bizid or br_bizid = @bizid
delete mps_biztype2  where biz2_bizid =@bizid 
delete mps_template where tmp_type = 'biz' and tmp_objid =@bizid 
  
 -- 删除存储过程      
 exec drop_autogenedproc @bizid
 
end