SqlServer判断数据库、表、字段、存储过程、函数是否存在

判断数据库是否存在 
if exists (select * from sys.databases where name = '数据库名')
--drop database [数据库名]

判断表是否存在
if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--drop table [表名]

if object_id(N'tablename',N'U') is not null
print '表存在'
else 
print '表不存在'

--判断某表的某字段是否存在  
if (not exists(select * from syscolumns where id=object_id('表明') and name='字段名'))  
print '字段存在'
else 
print '字段不存在'

判断存储过程是否存在
if exists (select * from sysobjects where id = object_id(N'[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
-- drop procedure [存储过程名]

判断函数是否存在 
IF OBJECT_ID (N'函数名') IS NOT NULL DROP FUNCTION dnt_split

判断数据库是否开启了全文搜索 
select databaseproperty('数据库名','isfulltextenabled')

判断全文目录是否存在 
select * from sysfulltextcatalogs where name ='全文目录名称'

猜你喜欢

转载自blog.csdn.net/smartsmile2012/article/details/78529510