9

我想访问 Sqlite 中任何特定表的所有特定视图。我知道我可以使用 sqlite_master 获取数据库中所有可用表的列表

SELECT name from sqlite_master WHERE type='table'; 

以及所有可用视图的列表

SELECT name from sqlite_master WHERE type ='view';

但我想找到特定表的所有可用视图。我怎么做 ?

4

2 回答 2

7

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.

于 2010-02-11T00:06:49.060 回答
1

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

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

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

SELECT name from sqlite_master 
  WHERE type ='view' AND charindex(Sql, "tableName") > 0;
于 2009-10-19T22:26:35.660 回答