是否有相当于 MySQL 的 DESCRIBE [table] 的 SQLite?
我刚刚开始学习 SQLite。如果能够看到表的详细信息就好了,比如 MySQL 的 DESCRIBE [table]
。 PRAGMA table_info [table]
还不够好,因为它只有基本信息(例如,它不显示列是否是某种类型的字段)。 SQLite 有办法做到这一点吗?
I'm just getting started learning SQLite. It would be nice to be able to see the details for a table, like MySQL's DESCRIBE [table]
. PRAGMA table_info [table]
isn't good enough, as it only has basic information (for example, it doesn't show if a column is a field of some sort or not). Does SQLite have a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
SQLite 命令行实用程序 有一个
.schema TABLENAME
命令向您显示创建语句。The SQLite command line utility has a
.schema TABLENAME
command that shows you the create statements.您是否正在寻找用于生成表的 SQL?为此,您可以查询
sqlite_schema
表:Are you looking for the SQL used to generate a table? For that, you can query the
sqlite_schema
table:查看所有表:
查看特定表:
To see all tables:
To see a particular table:
为了防止人们被其他答案的某些评论误导:
.schema
或query from sqlite_master
没有给出任何输出,则表明不存在tablename
,例如,这也可能是由.schema
、.tables
、.. 末尾的;
分号引起的。或者只是因为该表确实不存在。.schema
不起作用的可能性很小,然后应该在 sqlite 项目中提交错误报告。sqlite
)比该语言提供包装器
/库
更有可能受到支持code> 对于每个程序(这不仅由于大量程序的本质而容易出现不完整性,而且还违背了单一源原则
,使维护变得复杂,进一步加剧了世界数据的混乱)。
To prevent that people are mislead by some of the comments to the other answers:
.schema
orquery from sqlite_master
not gives any output, it indicates a non-existenttablename
, e.g. this may also be caused by a;
semicolon at the end for.schema
,.tables
, ... Or just because the table really not exists.That
.schema
just doesn't work is very unlikely and then a bug report should be filed at the sqlite project.sqlite
, is more likely to be supported than that the language provides awrapper
/library
for every program (which not only is prone to incompleteness by the very nature of the masses of programs out there, but also is counter actingsingle-source principle
, complicatingmaintenance
, furthering the chaos of data in the world).与“PRAGMA”相比,“.schema”可以显示更多的表详细信息,包括表约束。
下面的命令显示所有表的详细信息:
下面的命令以格式良好的方式显示所有表的详细信息:
下面的命令显示以下的详细信息一张表:
下面的这些命令以格式良好的方式显示一张表的详细信息:
或者:
此外,下面的这些命令显示有关“.schema”的详细信息< /strong>:
或者:
然后,如下所示:
".schema" can show more details of tables including Table Constraints than "PRAGMA".
This command below shows the details of all tables:
This command below shows the details of all tables in a well-formatted way:
This command below shows the details of one table:
These commands below show the details of one table in a well-formatted way:
Or:
In addition, these commands below show the details about ".schema":
Or:
Then, this is how it looks like below:
如果您使用的是图形工具。它会在表名称旁边显示架构。如果是DB Browser For Sqlite,请单击打开数据库(右上角),导航并打开数据库,您将看到表中填充的信息,如下所示以下。
希望它能帮助一些无法使用命令行的初学者。
If you're using a graphical tool. It shows you the schema right next to the table name. In case of DB Browser For Sqlite, click to open the database(top right corner), navigate and open your database, you'll see the information populated in the table as below.
Hope it helped some beginner who failed to work with the commandline.
.schema user_meta
对我不起作用。但
.schema
确实向我展示了所有表格。我可以使用以下命令查看 user_meta 表:
.schema user_meta
didn't work for me.but
.schema
did show me all the tables.I was able to see user_meta table using this command:
例如,我的 Django SQLite 数据库中有这些表:
然后
为了描述和查看 shop_product 表的 SQL 语句,您可以运行以下命令:
插图
For example, I have these tables in my Django SQLite database:
Then
In order to describe and see the SQL statements for shop_product table, you can run the following command:
Illustration