Getting Started with SQLite

Installing SQLite

root@gwaihir# apt-get install sqlite3

Simple! I love apt!

Invoking SQLite

andrew@gwaihir$ sqlite3
SQLite version 3.3.13 
Enter ".help" for instructions 

This starts sqlite3 in interactive mode. Now you need a few commands.

The Four SQL Commands that you need to know

SQL Command #1: Create

sqlite> create table sources (title CHAR(80), author CHAR(40), page INT) ;

The create command creates a table. (It can create other objects too, but for now we will only work with tables. The fields of the table are given in a comma separated list. A semi-colon terminates every command.

SQL Command #2: insert

sqlite> insert into sources values("Nuclear Engineering 3rd Edition", "Bonilla", 234) ;

sqlite> insert into sources values("Introduction to Fluid Dynamics 2nd ed, "Fox & Mcdonald", 272) ;

The insert command adds more data to a table.

SQL Command #3: Update

sqlite> update sources set page = 300 where page = 272 ;

The update command changes fields in existing records.

SQL Command #4: Select

sqlite> select * from sqlite_master ;

table|sources|sources|2|CREATE TABLE sources( title CHAR(80) not null, author CHAR(40) not null, page INT)

sqlite> select * from sources;

Nuclear Engineering 3rd Edition|Bonilla|234
Introduction to Fluid Mechanics 2nd ed|Fox & Mcdonald|300

The select command shows the contents of tables that match search criterion.