How can I get the list of a columns in a table for a SQLite database?(如何获取 SQLite 数据库表中的列列表?)
问题描述
我希望检索表中的列列表.该数据库是 SQLite 的最新版本(我相信是 3.6).我正在寻找使用 SQL 查询执行此操作的代码.与列相关的元数据(例如长度、数据类型等...)的额外加分
I am looking to retrieve a list of columns in a table. The database is the latest release of SQLite (3.6, I believe). I am looking for code that does this with a SQL query. Extra bonus points for metadata related to the columns (e.g. length, data type, etc...)
推荐答案
您要查找的内容称为数据字典.在 sqlite 中,可以通过查询 sqlite_master 表(或视图?)找到所有表的列表
What you're looking for is called the data dictionary. In sqlite a list of all tables can be found by querying sqlite_master table (or view?)
sqlite> create table people (first_name varchar, last_name varchar, email_address varchar);
sqlite> select * from sqlite_master;
table|people|people|2|CREATE TABLE people (first_name varchar, last_name varchar, email_address varchar)
要获取列信息,您可以使用 pragma table_info(table_name)
语句:
To get column information you can use the pragma table_info(table_name)
statement:
sqlite> pragma table_info(people);
0|first_name|varchar|0||0
1|last_name|varchar|0||0
2|email_address|varchar|0||0
有关 pragma 语句的更多信息,请参阅文档.
For more information on the pragma statements, see the documentation.
这篇关于如何获取 SQLite 数据库表中的列列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取 SQLite 数据库表中的列列表?


基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01