1 判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] 2 判断表是否存在 if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [表名] 3 判断存储过程是否存在…
1.判断是否存在addOneArticle这个存储过程 if Exists(select name from sysobjects where NAME = 'addOneArticle' and type='P') drop procedure addOneArticle 2.判断是否存在countAr这个触发器 if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[countAr]') and OBJECTP…
判断表是否存在: 语法: SELECT * FROM dbo.SysObjects where id = object_id(N'表名') 例子: SELECT * FROM dbo.SysObjects where id = object_id(N'ExchangeLog') if exists(SELECT * FROM dbo.SysObjects where id = object_id(N'ExchangeLog')) print '表存在' else print '表不存在' 判断列…
下面为您介绍sql下用了判断各种资源是否存在的代码,需要的朋友可以参考下,希望对您学习sql的函数及数据库能够有所帮助.库是否存在if exists(select * from master..sysdatabases where name=N'库名')print 'exists'elseprint 'not exists'----------------- 判断要创建的表名是否存在if exists (select * from dbo.sysobjects where id = object…
--数据库是否存在 IF exists(SELECT * FROM master..sysdatabases WHERE name=N'库名') PRINT 'exists' ELSE PRINT 'not exists' --------------- -- 判断要创建的表名是否存在 ) -- 删除表 DROP TABLE [dbo].[表名] GO --------------- --判断要创建临时表是否存在 IF Object_Id('Tempdb.dbo.#Test') Is Not N…
if object_id(N'tablename',N'U') is not nulldrop table tablenamego if exists (select * from sysobjects where id = object_id(N'[dbo].[tbname]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[tbname]go…