gpt4 book ai didi

Python 数据库;如何查找odbc中的所有表

转载 作者:太空狗 更新时间:2023-10-29 21:26:35 25 4
gpt4 key购买 nike

有什么方法可以通过 odbc 连接获取所有可用表的列表。

我必须从沿途生成的表中获取数据,因此我事先不知道名称。

最佳答案

(在回答此问题时未指定 ODBC 驱动程序)
来自PyODBC documentation :

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

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

编辑:作为使用“Anaconda ODBC”指定的 OP:

据我所知,无法直接从 PyWin32-odbc 访问这些数据(我认为这是 Anacondas 使用的)。根据您的基础数据库,它们可能是您可能查询的“系统表”。像 sys.objectsdbo.sysobjectsinformation_schema.tables 或...(RDBMS 供应商在该领域很有创意)。

请参阅底层 RDBMS 的文档以获取更多信息。或者(就我自己而言,我会强烈插入)提出安装更通用的 ODBC 驱动程序的请求...

关于Python 数据库;如何查找odbc中的所有表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25522873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com