我试图确定是否存在某个名称的数据库,如果不存在,则创建它。理想情况下,这将是在VBScript中。我目前正在尝试使用一个数组的循环搜索,但是数据库的总数会有很大的变化。

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

最佳答案

尝试:

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

如果不存在,将得到一个空结果集。
如果您需要知道数据库是否存在,以避免在创建它时出错:
CREATE DATABASE IF NOT EXISTS <name>;

10-08 05:59