如何用T-SQL语言判断一个数据库已创建?
能给个例子吗?

解决方案 »

  1.   

    select * from Sys.Databases where name ='yourdbname'
      

  2.   

    use master
    if exists(select 1 from sysdatabases where name = '数据库名')
       print '存在'
    else
       print '不存在'
      

  3.   

    if not exists(select 1 from Sys.Databases where name ='yourdbname')
    create database yourdbname
      

  4.   


    if db_id('test') is not null
    print 1
    else 
    print 0
      

  5.   

    IF  EXISTS (SELECT * FROM sys.databases WHERE name = 'dbname') 
    .....
      

  6.   

    if not exists(select 1 from sys.databases where name ='yourdbname')
    ...
      

  7.   

    大侠们要让楼主知道什么是sys.database,,强烈要求楼主去了解sysdatabase这个在master库中的表。
      

  8.   

    这是个很基础的东西if exists (select * from  sys.objects where object_id = object_id (N'[dbo].[UserInfo]') and type in (N'U')  )