MSSQL.database_exists

MSSQL.database_exists(database_name=None)[source]

Check whether a database exists.

Parameters:

database_name (str | None) – Name of the database to check; defaults to None.

Returns:

Whether the database exists.

Return type:

bool

Examples:

>>> from pyhelpers.dbms import MSSQL
>>> testdb = MSSQL(database_name='testdb')
Creating a database: [testdb] ... Done.
Connecting <server_name>@localhost:1433/testdb ... Successfully.
>>> # Check whether the database [testdb] exists now
>>> testdb.database_name
'testdb'
>>> testdb.database_exists(database_name='testdb')
True
>>> # Delete the database [testdb]
>>> testdb.drop_database(verbose=True)
To drop the database [testdb] from <server_name>@localhost:1433
? [No]|Yes: yes
Dropping [testdb] ... Done.
>>> # Check again whether the database [testdb] still exists now
>>> testdb.database_exists(database_name='testdb')
False
>>> testdb.database_name
'master'