SQLite basics

SQLite is a serverless relational database. It is used notably by modern browsers like Chrome and Firefox to store data like history, cookies, saved passwords…

We are going to see how you can get around in the command line interface. To work with a database file you can start the program in this way:

What you get is a prompt similar to the mysql client. Now let’s see what tables are available:

If we want to see column names we can use the .schema command:

To customize the output format of query results you can use the .mode and .headers options, for example:

You can add these options to .sqliterc for permanent effect. Finally, if you want to exit just type .exit

-> Something annoying about sqlite is that the ALTER TABLE command is very limited. You can only rename a table or add a column, but you can’t modify or delete columns after they have been created. There is an official work-around for this, explained here: https://www.sqlite.org/lang_altertable.html

Using SQLite in Ruby: https://rubygems.org/gems/sqlite3

You might also like:
Redis: the blazing fast datastore

Leave a Reply