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?
views:
275answers:
3
+3
A:
The SQLite command line utility has a .schema TABLENAME
command that shows you the create statements.
Ned Batchelder
2010-07-25 18:27:50
+2
A:
To see all tables:
.tables
To see a particular table:
.schema [tablename]
beamrider9
2010-07-25 18:28:49
+4
A:
Are you looking for the SQL used to generate a table? For that, you can query the sqlite_master
table:
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)
Mark Rushakoff
2010-07-25 18:29:37
Is there any difference between this and `.schema foo`?
Matthew
2010-07-25 18:45:34
@Matthew: `.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
2010-07-25 21:09:52