IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[droptable]') AND type = 'P')
DROP PROCEDURE [dbo].[droptable]
GO
CREATE procedure [dbo].[droptable](@tbid int)
as
begin
declare @s1 varchar(20) 
declare @sql nvarchar(1000)
set @s1 = convert(varchar(20),@tbid) 
if (object_id(N'order_'+@s1,N'U') is not null)  
begin
set @sql = 'drop table order_'+@s1 
execute(@sql) 
end

declare @i int
set @i=0 
while (@i<200)
begin
if (object_id(N'order_'+@s1+'_'+convert(varchar(10),@i),N'U') is not null)  
begin
set @sql = 'drop table order_'+@s1+'_'+convert(varchar(10),@i) 
execute(@sql) 
end
set @i = @i + 1 
end

if (object_id(N'order_'+@s1+'_users',N'U') is not null)  
begin
set @sql = 'drop table order_'+@s1+'_users'  
execute(@sql) 
end

if (object_id(N'order_'+@s1+'_relation',N'U') is not null)  
begin
set @sql = 'drop table order_'+@s1+'_relation'  
execute(@sql) 
end

delete mps_fieldinfo_operation where fldi_tbtype='biz' and fldi_tbid=@tbid 

delete mps_fieldinfo where fldi_tbtype='biz' and fldi_tbid=@tbid 

delete  mps_biztype_comefrom where bs_bizid=@tbid 
delete mps_biztype_comefrom where bs_stype='biz' and bs_sbizid=@tbid 

delete  mps_biztype2 where biz2_bizid = @tbid 

delete mps_biztype_source where bizs_type='biz' and bizs_bizid=@tbid 
delete mps_biztype_source where bizs_sourcetype='biz' and bizs_ctgid=@tbid 
end