选择请求中的编译指示

Vya*_*lav 9 sql sqlite pragma

我想在 SQLite 的表中检索列的名称和行数。这是一个命令吗?

SELECT COUNT(*) FROM tablename
Run Code Online (Sandbox Code Playgroud)

PRAGMA table_info(tablename))
Run Code Online (Sandbox Code Playgroud)

szm*_*618 13

接受的答案是正确的,但现在已经过时了,因为 SQLite 3.16.0 你可以使用PRAGMA 函数

所以你现在可以写:

SELECT * FROM pragma_table_info('tablename') JOIN (SELECT COUNT(*) FROM tablename);
Run Code Online (Sandbox Code Playgroud)

或者,如果您真的只需要名称:

SELECT name, rowcount FROM pragma_table_info('tablename') JOIN (SELECT COUNT(*) AS rowcount FROM tablename);
Run Code Online (Sandbox Code Playgroud)

(在 SQLite 3.25.2 中测试)

使用它需要您自担风险:

This feature is experimental and is subject to change. Further documentation will become available if and when the table-valued functions for PRAGMAs feature becomes officially supported.


CL.*_*CL. 4

PRAGMA 是一个单独的命令,而不是(子)查询,并且不能与其他 SQL 语句组合。