How to check if the database exists or not in rails before doing a rake db:setup

后端 未结 7 1307
你的背包
你的背包 2020-12-05 23:58

How to check if the database exists or not in rails before doing a rake db:setup?

I would like to check if a database already exists before a db:create is being done

7条回答
  •  鱼传尺愫
    2020-12-06 00:03

    TRY THIS

     IF EXISTS 
           (
             SELECT name FROM master.dbo.sysdatabases 
            WHERE name = N'New_Database'
            )
        BEGIN
            SELECT 'Database Name already Exist' AS Message
        END
        ELSE
        BEGIN
            CREATE DATABASE [New_Database]
            SELECT 'New Database is Created'
        END
    

提交回复
热议问题