如何列出 SQLite 中特定表的所有可用视图?

发布于 2024-08-07 19:05:22 字数 280 浏览 3 评论 0原文

我想访问 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒江雪… 2024-08-14 19:05:22

无需使用extension-functions.c;只需使用“LIKE”运算符:

SELECT name FROM sqlite_master WHERE type = 'view' and sql LIKE "%_tablename_%";

当然,如果您的表名包含其他表名作为子字符串,或者是常见 SQL 保留字(如“here”或“rom”)的子字符串,您将得到错误的匹配。您可以通过以下方式消除后者:

SELECT name FROM sqlite_master WHERE type = 'view' AND sql LIKE "% FROM %tablename% WHERE %";

提供您试图找到的符合典型模型的视图。

No need to use extension-functions.c; just use the "LIKE" operator:

SELECT name FROM sqlite_master WHERE type = 'view' and sql LIKE "%_tablename_%";

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:

SELECT name FROM sqlite_master WHERE type = 'view' AND sql LIKE "% FROM %tablename% WHERE %";

providing the views you're trying to find conform to the typical model.

榆西 2024-08-14 19:05:22

使用extension-functions.c 中的charindex 函数在sqlite_master 中的Sql 列中搜索表的名称。

extension-functions.c(查看此页面的底部)是一个用户-贡献的模块,使用可加载扩展机制为 SQL 查询提供数学和字符串扩展函数。

您的最终查询应如下所示(未经测试):

SELECT name from sqlite_master 
  WHERE type ='view' AND charindex(Sql, "tableName") > 0;

Use the charindex function in extension-functions.c to search the Sql column in sqlite_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):

SELECT name from sqlite_master 
  WHERE type ='view' AND charindex(Sql, "tableName") > 0;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文