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


当前回答

使用.da查看所有数据库-其中一个被称为“main”。

该数据库的表可以通过以下方式查看:

SELECT distinct tbl_name from sqlite_master order by 1;

附加的数据库需要在ATTACH语句中用AS选择前缀,例如aa (, bb, cc…),因此:

SELECT distinct tbl_name from **aa.sqlite_master** order by 1;

请注意,在这里您也可以获得视图。要排除这些,请添加:

where type = 'table'

在order之前

其他回答

”。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);

使用.da查看所有数据库-其中一个被称为“main”。

该数据库的表可以通过以下方式查看:

SELECT distinct tbl_name from sqlite_master order by 1;

附加的数据库需要在ATTACH语句中用AS选择前缀,例如aa (, bb, cc…),因此:

SELECT distinct tbl_name from **aa.sqlite_master** order by 1;

请注意,在这里您也可以获得视图。要排除这些,请添加:

where type = 'table'

在order之前

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

SELECT name FROM sqlite_master
WHERE type='table';

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

.table

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

试试PRAGMA table_info(table-name); http://www.sqlite.org/pragma.html#schema