gpt4 book ai didi

sql - 如何在 SQLite 中列出特定表的所有可用 View ?

转载 作者:IT王子 更新时间:2023-10-29 06:24:05 26 4
gpt4 key购买 nike

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

SELECT name from sqlite_master WHERE type='table'; 

以及所有可用 View 的列表,使用

SELECT name from sqlite_master WHERE type ='view';

但我想查找特定表的所有可用 View 。我怎么做 ?

最佳答案

无需使用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 %";

提供您要查找的 View 符合典型模型。

关于sql - 如何在 SQLite 中列出特定表的所有可用 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1591405/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com