从 sqlite 数据库获取信息模式

发布于 2025-01-04 07:16:38 字数 506 浏览 2 评论 0原文

我想从当前数据库获取所有表及其列的列表,例如:

 table1
  - column1
  - column2
  - column3
 table2
  - column1
  - column2

我尝试过:

SELECT * FROM sqlite_master WHERE type=? ORDER BY name;

(? is 'table')

但我只得到表列表,没有列:(

如果我删除 WHERE 子句,我得到这个错误:

SQLSTATE[HY000]: General error: 25 bind or column index out of range

如果我用 column 替换 table 我什么也得不到......

请帮忙?

I want to get a list of all tables and their columns from the current database, like:

 table1
  - column1
  - column2
  - column3
 table2
  - column1
  - column2

I tried:

SELECT * FROM sqlite_master WHERE type=? ORDER BY name;

(? is 'table')

but I get only the table list, without the columns :(

If I remove the WHERE clause I get this error:

SQLSTATE[HY000]: General error: 25 bind or column index out of range

If I replace table with column I get nothing...

Help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事↓在人 2025-01-11 07:16:38

尝试这个查询:

pragma table_info(table1);

您将得到以下列:

cid // Column Id
name // Column Name
type // Column Type
notnull // If the column is not null
dflt_value // Column default Value
pk // If the column is a primary key

Try this query:

pragma table_info(table1);

You'll get the following columns:

cid // Column Id
name // Column Name
type // Column Type
notnull // If the column is not null
dflt_value // Column default Value
pk // If the column is a primary key
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文