MSSQL.create_cursor¶
- MSSQL.create_cursor(database_name=None)[source]¶
Create a pyodbc cursor.
- Parameters:
database_name (str | None) – Name of the database to connect to; defaults to the name of the currently-connected database if
database_name=None
.- Returns:
A pyodbc cursor.
- Return type:
pyodbc.Cursor
Examples:
>>> from pyhelpers.dbms import MSSQL >>> mssql = MSSQL(verbose=True) Connecting <server_name>@localhost:1433/master ... Successfully. >>> db_cur = mssql.create_cursor() >>> # Get information about all tables in the database [master] >>> tables_in_db = db_cur.tables(schema='dbo', tableType='TABLE') >>> list(tables_in_db) [('master', 'dbo', 'MSreplication_options', 'TABLE', None), ('master', 'dbo', 'spt_fallback_db', 'TABLE', None), ('master', 'dbo', 'spt_fallback_dev', 'TABLE', None), ('master', 'dbo', 'spt_fallback_usg', 'TABLE', None), ('master', 'dbo', 'spt_monitor', 'TABLE', None)] >>> db_cur.close()