如何列出 SQLite 中特定表的所有可用视图?
我想访问 Sqlite 中任何特定表的所有特定视图。我知道我可以使用 sqlite_master 获取数据库中所有可用表的列表,
SELECT name from sqlite_master WHERE type='table';
并使用使用所有可用视图的列表
SELECT name from sqlite_master WHERE type ='view';
但我想找到特定表的所有可用视图。我该怎么做?
I want to access all the particular views of any particular table in Sqlite . I know I can get the list of all the available tables in the database using sqlite_master
SELECT name from sqlite_master WHERE type='table';
And the list of all the available views using
SELECT name from sqlite_master WHERE type ='view';
But I want to find all the available views for a particular table . How do I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需使用extension-functions.c;只需使用“LIKE”运算符:
当然,如果您的表名包含其他表名作为子字符串,或者是常见 SQL 保留字(如“here”或“rom”)的子字符串,您将得到错误的匹配。您可以通过以下方式消除后者:
提供您试图找到的符合典型模型的视图。
No need to use extension-functions.c; just use the "LIKE" operator:
You will get false matches, of course, if you have table names that contain other table names as substrings, or that are substrings of common SQL reserved words (like "here" or "rom"). You can eliminate the latter by the following:
providing the views you're trying to find conform to the typical model.
使用extension-functions.c 中的
charindex
函数在sqlite_master
中的Sql 列中搜索表的名称。extension-functions.c(查看此页面的底部)是一个用户-贡献的模块,使用可加载扩展机制为 SQL 查询提供数学和字符串扩展函数。
您的最终查询应如下所示(未经测试):
Use the
charindex
function in extension-functions.c to search the Sql column insqlite_master
for the name of your table.extension-functions.c (look at the bottom of this page) is a user-contributed module that provides mathematical and string extension functions for SQL queries, using the loadable extensions mechanism.
Your final query should look something like this (not tested):