views:

275

answers:

3

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?

+3  A: 

The SQLite command line utility has a .schema TABLENAME command that shows you the create statements.

Ned Batchelder
+2  A: 

To see all tables:

.tables

To see a particular table:

.schema [tablename]
beamrider9
+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
Is there any difference between this and `.schema foo`?
Matthew
@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