表中某个栏位的判断:
if col_length('TC_Card','CardValueBZXF') is null –判断表TC_Card中CardValueBZXF栏位是否为NULL
某个表是否存在的判断:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TC_CardTypeChange]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) --判断TC_CardTypeChange这个表是否存在
存储过程是否存在的判断:
If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_SubsidyContrast_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) --判断存储过程usp_SubsidyContrast_Update是否存在
判断视图是否存在:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[v_XFAndJS]') and OBJECTPROPERTY(id, N'IsView') = 1)
判断函数是否存在:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Int2IP]') and xtype in (N'FN', N'IF', N'TF'))
判断字段描述是否存在:
IF EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'USER',N'dbo', N'TABLE',N'YC_ECMeter', N'COLUMN',N'WaterPriceID'))
判断字段是否存在
if not exists(select * from syscolumns where id=object_id('dd') and name='OperatorState')