This tutorial is a small introduction to databases, SQL language and
the simplest
way to get started on using an embedded small database for uses which
are common.
To begin with my understanding of SQL and databases has been very sketchy
and incongruous for a long time.
In recent years however things changed. Today I can claim that I put SQL to
good use.
To put things in perspective, other than crazy fellows like my ilk
most of the world
lives and moves on databases.
All your ticketing, bank transactions blah blah are done using DB.
So learning SQL is something that a lot of average programmers and
grubby folks do
grudgingly.
But properly applied, sqlite and SQL are both very pleasant.
Okay let us start from the start.
I will split this content into two mails. In this mail I will start with sqlite.
What is sqlite?
It is a very small database that supports the SQL standard or is
compliant to a large degree.
There are really small key value pair(table) databases like tdb in
samba, Berkeley DB, gdm etc.
But no SQL.
SQL = Structured Query Language
It is a method to extract data which is basically columns from a set of rows.
Okay, let us look at a trivial example.
Say you have a very simple data set(table).
A table is nothing but a name value pair.
Each row in a database is a separate data point or name value pair .
Usually it is one name and one value or multiple values.
Does not matter much. But each row is always the smallest unit of
independent data.
Let us look at it this way.
I want to store and manipulate the marks of students in a class.
There are 5 subjects, phy, che, math, Tamil and English.
Okay here you go:
Rahim 20 30 40 50 100
Syam 20 40 40 50 100
Priya 30 50 100 60 80
Okay you have 3 students with their credentials.
Now Each of them is represented in an SQL DB like this.
$ sqlite3 marks.db
> create table marks (id integer primary key, name string, phy
integer, che integer, mat integer,
eng integer, tamil integer);
insert into marks values(NULL, "Rahim", 20, 30, 40, 50, 100);
insert into marks values(NULL, "Syam", 20, 40, 40, 50, 100);
insert into marks values(NULL, "Priya", 30, 50, 100, 60, 80);
quit;