判断数据库
if exists(select 1 from sys.databases where name=N‘[数据库名]‘)
判断表
if exists (select 1 from dbo.sysobjects where id = object_id(N‘[dbo].[表名]‘) and objectproperty(id, N‘IsTable‘) = 1)
判断字段
if exists(select 1 from syscolumns where id=OBJECT_ID(N‘[dbo].[表名]‘) and name=N‘[字段名]‘))
判断存储过程
if exists (select 1 from dbo.sysobjects where id = object_id(N‘[dbo].[存储过程名]‘) and OBJECTPROPERTY(id, N‘IsProcedure‘) = 1)
T-SQL常用数据库对象判断语句,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/skykrf/p/3798790.html