是否有与 MySQL 的 DESCRIBE [table] 等效的 SQLite?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3330435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an SQLite equivalent to MySQL's DESCRIBE [table]?
提问by Matthew
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?
我刚刚开始学习SQLite。能够查看表的详细信息会很好,例如 MySQL 的DESCRIBE [table]
. PRAGMA table_info [table]
不够好,因为它只有基本信息(例如,它不显示列是否属于某种类型的字段)。SQLite 有办法做到这一点吗?
回答by Ned Batchelder
The SQLite command line utilityhas a .schema TABLENAME
command that shows you the create statements.
在SQLite的命令行实用程序有一个.schema TABLENAME
命令,显示你的创建语句。
回答by Strater
PRAGMA table_info([tablename]);
回答by Mark Rushakoff
Are you looking for the SQL used to generate a table? For that, you can query the sqlite_master
table:
您在寻找用于生成表的 SQL 吗?为此,您可以查询sqlite_master
表:
sqlite> CREATE TABLE foo (bar INT, quux TEXT);
sqlite> SELECT * FROM sqlite_master;
table|foo|foo|2|CREATE TABLE foo (bar INT, quux TEXT)
sqlite> SELECT sql FROM sqlite_master WHERE name = 'foo';
CREATE TABLE foo (bar INT, quux TEXT)
回答by Ross Snyder
To see all tables:
查看所有表格:
.tables
To see a particular table:
要查看特定表:
.schema [tablename]
回答by Radagast
To prevent that people are mislead by some of the comments to the other answers:
为了防止人们被其他答案的一些评论误导:
- If
.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.
- 如果
.schema
还是query from sqlite_master
没有提供任何输出,则表示不存在的tablename
,比如,这也可以由引起;
分号结束了.schema
,.tables
......或者仅仅因为表真的不存在。这.schema
不太可能起作用,然后应该在 sqlite 项目中提交错误报告。
... .schema can only be used from a command line; the above commands > can be run as a query through a library (Python, C#, etc.). – Mark Rushakoff Jul 25 '10 at 21:09
... .schema 只能从命令行使用;上述命令 > 可以通过库(Python、C# 等)作为查询运行。– 马克·拉沙科夫 10 年 7 月 25 日,21:09
- 'can only be used from a command line' may mislead people. Almost any (likely every?) programming language can call other programs/commands. Therefore the quoted comment is unlucky as calling another program, in this case
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).
- “只能从命令行使用”可能会误导人们。几乎所有(可能是每个?)编程语言都可以调用其他程序/命令。因此引用的注释是不幸的,因为调用另一个程序,在这种情况下
sqlite
,比语言为每个程序提供一个wrapper
/的语言更有可能得到支持library
(这不仅由于大量程序的本质而易于不完整) ,但也是反作用single-source principle
,复杂化maintenance
,进一步加剧世界上数据的混乱)。
回答by Mujeeb Ishaque
Ifyou'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.
如果您使用的是图形工具。它会在表名旁边显示架构。在DB Browser For Sqlite 的情况下,单击打开数据库(右上角),导航并打开数据库,您将看到下表中填充的信息。
right click on the record/table_name, click on copy create statementand there you have it.
右键单击记录/表名,单击复制创建语句,就可以了。
Hope it helped some beginner who failed to work with the commandline.
希望它可以帮助一些无法使用命令行的初学者。