sql判断各种类型的东西是否存在

来源:互联网 发布:java面向对象试题 编辑:程序博客网 时间:2024/05/22 14:05

表中某个栏位的判断:

if col_length('TC_Card','CardValueBZXF') is null –判断表TC_CardCardValueBZXF栏位是否为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'))

0 0
原创粉丝点击