# SQLite
## Schema Inspection
```sql
.tables -- list all tables
.schema -- show all CREATE statements
.schema <table> -- show CREATE for a specific table
```
## Example Session
```sql
$ sqlite3 mydb.sqlite
SQLite version 3.46.0
Enter ".help" for instructions
sqlite> .tables
addresses messages threads
sqlite> .schema messages
CREATE TABLE messages (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
subject TEXT, sender TEXT, date INTEGER);
```
## Useful Dot Commands
| Command | Description |
|---------|-------------|
| `.tables` | List tables |
| `.schema [table]` | Show CREATE statements |
| `.headers on` | Show column headers in output |
| `.mode column` | Columnar output format |
| `.mode csv` | CSV output format |
| `.import file table` | Import CSV into table |
| `.dump [table]` | Export as SQL |
| `.help` | List all dot commands |
## Querying the Schema Directly
SQLite stores schema in the `sqlite_master` table:
```sql
SELECT name, type FROM sqlite_master WHERE type = 'table';
SELECT sql FROM sqlite_master WHERE name = 'messages';
```