您的位置:首页 > 博客中心 > 数据库 >

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

时间:2022-03-10 17:42

判断数据库

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

热门排行

今日推荐

热门手游