MSSQL.read_columns

MSSQL.read_columns(table_name, column_names, dtype=None, schema_name=None, chunk_size=None, **kwargs)[source]

Read data of specific columns of a table.

Parameters:
  • table_name (str) – Name of a table in the currently-connected database.

  • column_names (list | tuple) – Column name(s) of the specified table.

  • dtype (str | None) – data type; options are {'hierarchyid', 'varbinary', 'geometry'}; defaults to None.

  • schema_name (str | None) – Name of a schema, defaults to DEFAULT_SCHEMA when schema_name=None.

  • chunk_size (int | None) – Number of rows to include in each chunk (if specified); defaults to None

  • kwargs – [Optional] Additional parameters for the function pandas.read_sql().

Returns:

Data of specific columns of the queried table.

Return type:

pandas.DataFrame

Examples:

>>> from pyhelpers.dbms import MSSQL
>>> from pyhelpers._cache import example_dataframe
>>> 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']}
>>> mssql.read_columns('MSreplication_options', column_names=['optname', 'value'])
          optname  value
0   transactional   True
1           merge   True
2  security_model   True

See also