判断数据库中要创建的存储过程、函数等是否已经存在
1.判断要创建的表是否已经存在
if exists (select * from sysobjects where id=OBJECT_ID(N'[dbo].[GetNdemoApplyDetail]') and OBJECTPROPERTY(id,N'IsUserTable')=1)
2.判断要创建的存储过程是否已经存在
if exists (select * from sysobjects where id=OBJECT_ID(N'[dbo].[存储过程名称]') and OBJECTPROPERTY(id,N'IsProcedure')=1) drop procedure [dbo].[存储过程名称]
3.判断要创建的视图是否已经存在
if exists (select * from sysobjects where id=OBJECT_ID(N'[dbo].[视图名称]') and OBJECTPROPERTY(id,N'IsVIew')=1) drop View [dbo].[视图名称]
4.判断要创建的函数是否已经存在
if exists (select * from sysobjects where id=OBJECT_ID(N'[dbo].[GetNdemoApplyDetail]') and xtype in (N'FN',N'IF',N'TF')) drop function [dbo].[函数名称] go if col_length('表名','列名') is null print '不存在' select 1 from sysobjects where id in (select id from syscolumns where name='列名') and name='表名'