IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_tool_delete_biz_tables]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_tool_delete_biz_tables]
GO
CREATE procedure [dbo].[mps_tool_delete_biz_tables](
@cmpid int ,
@tablename varchar(100) 
) as
begin
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
declare newords cursor LOCAL  FORWARD_ONLY READ_ONLY  
  for select biz_id from mps_biztype where biz_cmpid=@cmpid 
  open newords  
  declare @bizid int 
  declare @sql nvarchar(1000) 
  FETCH NEXT FROM newords INTO   @bizid
  WHILE (@@FETCH_STATUS = 0)  
  BEGIN  
exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 
set @sql = 'drop table '+@dbname+@tbname+@tablename 
delete mps_fieldinfo where fldi_cmpid=@cmpid and  fldi_tbtype='biz' and fldi_tbid=@bizid and fldi_tbname=@tbname+@tablename 
print @sql 
execute(@sql) 
  FETCH NEXT FROM newords INTO   @bizid 
  END  
  CLOSE newords  
  DEALLOCATE newords   
end