如何列出所有表或仅列出给定数据库的表
您可以使用以下命令获取数据库列表
PRAGMA database_list
或使用“主”数据库中的表列表
select name from sqlite_master where type='table'
,但正如我刚刚所写,它仅返回“主”数据库中的表,而且我没有办法知道哪些表表位于其他数据库中。
那么如何列出其他数据库中的表(稍后附上)呢?
谢谢,--DD
PS:我可以想到一种解决方法,为通过编译指示database_list列出的每个数据库创建一个单独的sqlite*,然后他们对这些(从sqlite_master中选择名称,其中type='table'”执行N次(因为现在每个都是“主要”),但这听起来应该是可能的,而无需诉诸解决方法,不是吗???
You can get a list of databases using
PRAGMA database_list
or a list of tables in the "main" database using
select name from sqlite_master where type='table'
but as I just wrote, it only returns the tables from the "main" DB only, and I don't see a way to know which tables are in the other DBs.
So how does one list the tables in the other DBs (which were attached later on)?
Thanks, --DD
PS: I can think of a work around of creating a separate sqlite* for each DB listed via the pragma database_list, and them doing the "select name from sqlite_master where type='table'" N times on those (since each one is the "main" one now), but this sounds like something that should be possible without resorting to the work-around, no???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊啊,通过查看 如何在 sqlite3 中打开内存数据库文件
由于每个数据库都有一个 sqlite_master,因此我需要做的就是在 sqlite_master 前面加上“DB_name”前缀。 其中 DB_name 对应于 PRAGMA database_list 返回的名称列。
Ah ah, found the answer by looking at the answer for How do I open an in-memory database file into sqlite3
Since there's a sqlite_master per DB, all I need to do is prefix sqlite_master with "DB_name." where DB_name corresponds to the name column returned by PRAGMA database_list.