SQLite basics
SQLite is a serverless relational database. It is used notably by modern browsers like Chrome Clinica Stomatologie Bucuresti curs valutar crama lechinta Psiholog Cluj 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:
sqlite3 data.db
sqlite>
What you get is a prompt similar to the mysql client. Now let’s see what tables are available:
sqlite> .tables
machines services
If we want to see column names we can use the .schema command:
sqlite> .schema machines
CREATE TABLE machines (id integer PRIMARY KEY AUTOINCREMENT, ip varchar(20), host varchar(100), os varchar(50));
To customize the output format of query results you can use the .mode and .headers options, for example:
sqlite> .headers on
sqlite> .mode column
sqlite> select * from machines;
id ip host os
---------- ------------ ---------- ---------------------------------
233 42.137.222.1 Cisco 827H ADSL router (IOS 12.2)
234 42.137.222.2 Cisco 1700-series router
235 42.137.222.3 Cisco 870 router or 2960 switch
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