什么SQL可以用来列出表,以及在SQLite数据库文件中的这些表中的行-一旦我已经附加了它与SQLite 3命令行工具上的ATTACH命令?


当前回答

对于SQLite 3的最新版本,您可以发布:

.fullschema

查看所有的create语句。

其他回答

通过union all,将所有表合并到一个列表中。

select name
from sqlite_master 
where type='table'

union all 

select name 
from sqlite_temp_master 
where type='table'

使用.help检查可用的命令。

.table

这个命令将显示当前数据库下的所有表。

在SQLite命令行中有一个命令可用:

.tables ?PATTERN?      List names of tables matching a LIKE pattern

它转换为以下SQL:

SELECT name FROM sqlite_master
WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'
UNION ALL
SELECT name FROM sqlite_temp_master
WHERE type IN ('table','view')
ORDER BY 1

我使用这个查询来获得它:

SELECT name FROM sqlite_master WHERE type='table'

在iOS中使用:

NSString *aStrQuery=[NSString stringWithFormat:@"SELECT name FROM sqlite_master WHERE type='table'"];

根据文档,相当于MySQL的SHOW TABLES;是:

”。“Tables”命令类似于设置列表模式然后执行 查询:

SELECT name FROM sqlite_master
  WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'
UNION ALL
SELECT name FROM sqlite_temp_master
  WHERE type IN ('table','view')
ORDER BY 1;

但是,如果您正在检查单个表是否存在(或获取其详细信息),请参阅LuizGeron的答案。