我希望能够访问Sqlite中任何特定表的所有特定视图。我知道可以使用sqlite_master获取数据库中所有可用表的列表。
SELECT name from sqlite_master WHERE type='table';
以下是所有可用视图的列表,使用
SELECT name from sqlite_master WHERE type ='view';
但我想找到特定表的所有可用视图。我该怎么做?
我希望能够访问Sqlite中任何特定表的所有特定视图。我知道可以使用sqlite_master获取数据库中所有可用表的列表。
SELECT name from sqlite_master WHERE type='table';
以下是所有可用视图的列表,使用
SELECT name from sqlite_master WHERE type ='view';
但我想找到特定表的所有可用视图。我该怎么做?
无需使用extension-functions.c;只需使用“LIKE”运算符:
SELECT name FROM sqlite_master WHERE type = 'view' and sql LIKE "%_tablename_%";
SELECT name FROM sqlite_master WHERE type = 'view' AND sql LIKE "% FROM %tablename% WHERE %";
在extension-functions.c中使用charindex
函数来搜索sqlite_master
中的Sql列,以查找您的表的名称。
extension-functions.c(请参考this page底部)是一个由用户贡献的模块,为SQL查询提供数学和字符串扩展函数,使用可加载扩展机制。
您的最终查询应该类似于以下内容(未经测试):
SELECT name from sqlite_master
WHERE type ='view' AND charindex(Sql, "tableName") > 0;