首页 > 代码库 > T-SQL常用数据库对象判断语句

T-SQL常用数据库对象判断语句

判断数据库

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, NIsTable) = 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, NIsProcedure) = 1)