判断数据库
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常用数据库对象判断语句
时间: 2024-11-06 05:51:21