How to View a Table’s Structure – Sqlite3

Just a quick post on how to view a table’s structure in SQLite3. Again, not something I’ve broken yet – more something I seem to keep forgetting. Simply start Sqlite:
chris@chris-VirtualBox:~/site$ sqlite3 -line db/development.sqlite3
SQLite version 3.7.4
Enter “.help” for instructions
Enter SQL statements terminated with a “;”

Then enter the following: – substituting orders for whatever your table name happens to be:
sqlite> pragma table_info(orders);
cid = 0
name = id
type = INTEGER
notnull = 1
dflt_value =
pk = 1

cid = 1
name = user_id
type = integer
notnull = 0
dflt_value =
pk = 0

cid = 3
name = created_at
type = datetime
notnull = 0
dflt_value =
pk = 0

Good Luck!

Leave a Reply