您的位置:首页 > 数据库

Sql Server判断数据库、表、存储过程、函数是否存在

2013-06-23 23:06 381 查看
判断数据库是否存在

if exists (select * from sys.databases where name = '数据库名')

drop database [数据库名]

sql server 中查询表或列是否存在确定表是否存在
1. 使用系统视图: sys.tables
select name from sys.tables where name = ' tablaName' and type = 'u'
type = 'u' 是排除存储过程和视图及系统表等,指的是用户表User_Table。
2. 使用系统视图:sysobjects

select * from sysobjects where id = object_id('UserSubsysCentHistory_null') and xtype = 'u'
xtype = 'u' 是排除存储过程和视图及系统表等,指的是用户表User_Table。

判断存储过程是否存在

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 ='全文目录名称'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐