您的位置:首页 > 数据库

判断数据库是否存在的两种方法

2011-03-11 09:46 260 查看
use master;
go
if db_id ('newdbTest') is not null---判断一个数据库是否存的方法一
begin
print ('newdbTest存在');
drop database newdbTest;--若存在则删除该数据库
print 'newdbTest已被删除';
end
go
print '重新创建数据库newdbTest'
create database newdbTest;--创建数据库newdb
go
if exists
(
select *
from master..sysdatabases --该行换为from sysdatabases也可
where name='newdbTest'
)--判断一个数据库是否存的方法二
begin
print 'newdbTest 已经存在';
end



以上是我在SQL 2005上运行的结果!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: