SQLite Cheat Sheet

Some notes on using SQLite

Opening a database

    mcvady@b:/tmp$ sqlite3 sqlite.db

Show tables

sqlite> .tables
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /tmp/sqlite.db                                            
sqlite> .tables
acc                  globalblacklist      purplemap          
active_watchers      grp                  re_grp             
address              htable               rls_presentity     
aliases              imc_members          rls_watchers       
carrier_name         imc_rooms            sca_subscriptions  
carrierfailureroute  lcr_gw               silo               
carrierroute         lcr_rule             sip_trace          
cpl                  lcr_rule_target      speed_dial

Describe a table

sqlite> .schema TABLENAME

Create a table

sqlite> CREATE TABLE connection(connection_id BIGINT, username STRING);

Insert into a table

sqlite> INSERT INTO connection (connection_id, username) VALUES (1, 'mcvady');

Dump output into a file

sqlite> .output SCHEMA_DUMP
sqlite> .schema

Run SQL commands from file into a DB

$ sqlite3 sqlite3.db < schema.sql