MSSQL.table_exists

MSSQL.table_exists(table_name, schema_name=None)[source]

Check whether a table exists.

Parameters:
  • table_name (str) – Name of the table to check.

  • schema_name (str | None) – Name of the schema where the table is located; defaults to DEFAULT_SCHEMA (i.e. 'dbo') if schema_name=None.

Returns:

Whether the table exists in the currently-connected database.

Return type:

bool

Examples:

>>> from pyhelpers.dbms import MSSQL
>>> mssql = MSSQL(verbose=True)
Connecting <server_name>@localhost:1433/master ... Successfully.
>>> mssql.table_exists(table_name='test_table')
False
>>> mssql.get_table_names()
{'dbo': ['MSreplication_options',
  'spt_fallback_db',
  'spt_fallback_dev',
  'spt_fallback_usg',
  'spt_monitor']}
>>> mssql.table_exists(table_name='MSreplication_options')
True