MSSQL.has_dtypes¶
- MSSQL.has_dtypes(table_name, dtypes, schema_name=None)[source]¶
Check whether a table contains columns of specified data types.
- Parameters:
table_name (str) – Name of the table in the currently-connected database.
dtypes (str | list) – Data type(s) to check for, e.g.
'geometry'
,'hierarchyid'
,'varbinary'
.schema_name (str | None) – Name of the schema where the table is located; defaults to
DEFAULT_SCHEMA
(i.e.'master'
) ifschema_name=None
.
- Returns:
Data type, whether the table has this data type and the corresponding column names.
- Return type:
Generator[str, bool, list]
Examples:
>>> from pyhelpers.dbms import MSSQL >>> mssql = MSSQL(verbose=True) Connecting <server_name>@localhost:1433/master ... Successfully. >>> mssql.get_table_names() {'dbo': ['MSreplication_options', 'spt_fallback_db', 'spt_fallback_dev', 'spt_fallback_usg', 'spt_monitor']} >>> res = mssql.has_dtypes(table_name='spt_monitor', dtypes='varbinary') >>> list(res) [('varbinary', False, [])] >>> res = mssql.has_dtypes(table_name='spt_monitor', dtypes=['geometry', 'int']) >>> list(res) [('geometry', False, []), ('int', True, ['cpu_busy', 'io_busy', 'idle', 'pack_received', 'pack_sent', 'connections', 'pack_errors', 'total_read', 'total_write', 'total_errors'])]