如何获取SQLite数据库表中的列列表? [英] How can I get the list of a columns in a table for a SQLite database?

查看:55
本文介绍了如何获取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数据库表中的列列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆