1、判断表'tab'是否存在 if (exists (SELECT * FROM dbo.sysobjects where id = object_id(N'tab')and OBJECTPROPERTY(id, N'IsUserTable') = 1)) DROP TABLE tab 1、判断是否存在ProcName存储过程 if Exists(select name from sysobjects where NAME = 'ProcName' and type='P') drop procedure ProcName 3、判断是否存在TicketView视图 IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = TicketView') DROP View TicketView 4、判断是否存在My_fun用户函数 (函数的类型 有两种,分别是表值函数'TF'-Table-valued Function 或标量值函数 'FN'-Scalar-valued Function ) if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[My_fun]') and (type = 'FN' or type = 'TF')) DROP FUNCTION My_fun 5、判断是否存在GenerateCode触发器 if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[GenerateCode]') and OBJECTPROPERTY(id, N'IsTrigger') = 1) drop trigger GenerateCode 6、判断数据库是否存在 if exists( select * from master.dbo.sysdatabases where dbid=db_ID( 'db' ) ) drop database db else print 'no exist db'
sql 判断存储过程、表、触发器、数据库、函数是否存在的语句
最新推荐文章于 2023-12-15 11:01:40 发布