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


当前回答

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

select name
from sqlite_master 
where type='table'

union all 

select name 
from sqlite_temp_master 
where type='table'

其他回答

”。Schema " commando将列出可用的表及其行,通过显示用于创建上述表的语句:

sqlite> create table_a (id int, a int, b int);
sqlite> .schema table_a
CREATE TABLE table_a (id int, a int, b int);

要列出表格,您还可以这样做:

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的答案。

要显示所有表,使用

SELECT name FROM sqlite_master WHERE type = "table"

要显示所有行,我认为可以遍历所有表,并在每个表上执行SELECT *。但也许垃圾场才是你想要的?

在SQLite数据库中查看表有几个步骤:

列出数据库中的表: .tables 列出表格的外观: . schema的表 打印整个表格: SELECT * FROM tablename; 列出所有可用的SQLite提示命令: .help