IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_check_field_exists]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_check_field_exists]
GO
CREATE procedure [dbo].[mps_check_field_exists](
@cmpid int,
@tbtype varchar(20),
@objidint,
@objid2int,
@fldname varchar(100) 
) as
begin
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
set nocount on
if (@tbtype='cst') 
begin
select top 1 @objid=ct_tag from mps_csttype with(nolock)  where ct_id=@objid 
end else 
if (@tbtype='prd') 
begin
select top 1 @objid=pc_tag from mps_prdctg  with(nolock) where pc_id=@objid 
end else 
if (@tbtype='equ') 
begin
select top 1 @objid=ec_tag from mps_equctg with(nolock)  where ec_id=@objid 
end  
if (exists (
select 1 from mps_fieldinfo  with(nolock) 
where fldi_cmpid=@cmpid and fldi_tbtype=@tbtype and 
fldi_tbid=@objid and  fldi_ord2tag=@objid2 and  fldi_fieldname=@fldname
)) 
begin
select '字段名'+@fldname+'已经存在，无法创建新字段' result 
end else
begin
select 'ok' result 
end 
set nocount off 
end