2

I'm trying to determine if a database of a certain name exists and then create it if it does not. Ideally this would be in VBScript. I currently am trying using a loop search of an array but the total number of databases will change greatly.

set dbQuery = ConnSQL.execute(checkDBsql) 
            if dbQuery.BOF and dbQuery.EOF then ' Query didn't return any records.
                ConnSQL.execute(MakeDb)
            else
                dbQuery.MoveFirst
                i = 0
                Do While Not dbQuery.EOF
                    i = i + 1
                loop
            end if
    set dbQuery = ConnSQL.execute(checkDBsql)
            if dbQuery.BOF and dbQuery.EOF then ' Query didn't return any records.
                msgBox "ERROR!"
            else
                e = 0
                do while not dbQuery.EOF
                    DBName(e) = dbQuery("Database")
                    e = e + 1
                loop                
                For a = 1 to UBound(DBName)
                    If DBName(a) = OldDBName Then
                        MsgBox DBName(a)
                    end if
                Next
    connSQL.close
0

3 Answers 3

4

Try:

SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DBName'

You'll get an empty resultset if not exists.

If you need to know if a database exists to avoid an error when trying to create it:

CREATE DATABASE IF NOT EXISTS <name>;
Sign up to request clarification or add additional context in comments.

1 Comment

The information Schema gave an error but the Create database if not exists part is what I was trying to do. I must have missed that.
1

if you can connect to the server in a mysql command line client

show databases

will show you the databases in mysql.

Comments

0

The quickest way is to issue:

show databases;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.