我想访问Sqlite中任何特定表的所有特定视图。我知道我可以使用SQLITE_MASTER如何列出SQLite中特定表的所有可用视图?
SELECT name from sqlite_master WHERE type='table';
和所有可用的视图中使用
SELECT name from sqlite_master WHERE type ='view';
列表获取数据库中所有可用的表的列表中,但我想找到所有可用的意见一个特定的表格。我怎么做 ?
我想访问Sqlite中任何特定表的所有特定视图。我知道我可以使用SQLITE_MASTER如何列出SQLite中特定表的所有可用视图?
SELECT name from sqlite_master WHERE type='table';
和所有可用的视图中使用
SELECT name from sqlite_master WHERE type ='view';
列表获取数据库中所有可用的表的列表中,但我想找到所有可用的意见一个特定的表格。我怎么做 ?
使用extension-functions.c中的charindex
函数在sqlite_master
中搜索Sql列以获取表的名称。
伸展functions.c(看的this page底部)是用户提供的模块,提供的数学和串扩展函数为SQL查询,使用加载扩展机制。
你最终的查询应该是这个样子(未测试):
SELECT name from sqlite_master
WHERE type ='view' AND charindex(Sql, "tableName") > 0;
无需使用延长-functions.c;只需使用“LIKE”操作符:
SELECT name FROM sqlite_master WHERE type = 'view' and sql LIKE "%_tablename_%";
你会得到错误匹配,当然,如果您有包含其他表名作为子,或者是常见的SQL保留字子(喜欢这里”表名“或”rom“)。您可以通过以下方式消除后者:
SELECT name FROM sqlite_master WHERE type = 'view' AND sql LIKE "% FROM %tablename% WHERE %";
提供您正在尝试查找的视图符合典型模型。