什么SQL可以用来列出表,以及在SQLite数据库文件中的这些表中的行-一旦我已经附加了它与SQLite 3命令行工具上的ATTACH命令?
当前回答
我使用这个查询来获得它:
SELECT name FROM sqlite_master WHERE type='table'
在iOS中使用:
NSString *aStrQuery=[NSString stringWithFormat:@"SELECT name FROM sqlite_master WHERE type='table'"];
其他回答
使用.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之前
在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
试试PRAGMA table_info(table-name); http://www.sqlite.org/pragma.html#schema
对于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'
推荐文章
- 选项(RECOMPILE)总是更快;为什么?
- 设置数据库从单用户模式到多用户
- oracle中的RANK()和DENSE_RANK()函数有什么区别?
- 的类型不能用作索引中的键列
- SQL逻辑运算符优先级:And和Or
- 如何检查一个表是否存在于给定的模式中
- 添加一个复合主键
- 如何在SQL Server Management Studio中查看查询历史
- 可以为公共表表达式创建嵌套WITH子句吗?
- 什么时候我需要在Oracle SQL中使用分号vs斜杠?
- SQL Server的NOW()?
- 在SQL中,count(列)和count(*)之间的区别是什么?
- 在SQL Server中截断(不是四舍五入)小数位
- 仅在Datetime列上按日期分组
- PostgreSQL通配符LIKE用于单词列表中的任何一个