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 数据库表中的列列表?


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01