Python odbc; how to find all tables in odbc

Is there a way to get a list of all tables available via odbc connection.

I need to get data from tables that are generated along the way and therefore I don't know the names in advance.

+3


source to share


1 answer


(no ODBC driver was listed at the time of this answer)
From PyODBC Documentation :

Most of the ODBC catalog functions are available as methods on cursor objects. The results are presented as SELECT results in the rows that are usually selected. The Cursor page documents these, but it may be helpful to refer to the Microsoft ODBC Documentation for more details.

cnxn   = pyodbc.connect(...)
cursor = cnxn.cursor()
for row in cursor.tables():
    print row.table_name

      




EDIT: as pointed out by the OP using "Anaconda ODBC":

As far as I know, there is no direct access to this data from PyWin32-odbc (which I think is what Anacondas uses). Depending on your underlying database, they might be a "system table" that you can query. Something like sys.objects

either or dbo.sysobjects

or information_schema.tables

or ... (RDBMS vendors are very creative in this area).

For more information refer to the basic RDBMS document. Or (on my own I would strongly insist on this), write a request to install a more generic ODBC driver ...

+7


source







All Articles