Introduction To SQLite
Introduction To SQLite
Introduction To SQLite
Introduction to SQLite
This is SQLite tutorial. It covers the SQLite database engine, sqlite3 command line tool and the SQL language
covered by the database engine. It is an introductory tutorial for the beginners. It covers SQLite 3.0 version.
SQLite database
worldwide in use today. SQLite is used in Solaris 10 and Mac OS operating systems, iPhone or Skype. Qt4 library
has a buit-in support for the SQLite as well as the Python or the PHP language. Many popular applications use
SQLite implements most of the SQL-92 standard for SQL. The SQLite engine is not a standalone process.
Instead, it is statically or dynamically linked into the application. SQLite library has a small size. It could take
less than 300 KiB. An SQLite database is a single ordinary disk file that can be located anywhere in the directory
hierarchy. It is a cross platform file. Can be used on various operating systems, both 32 and 64 bit architectures.
SQLite is created in C programming language and has bindings for many languages like C++, Java, C#, Python,
Perl, Ruby, Visual Basic, Tcl and others. The source code of SQLite is in public domain.
Definitions
A relational database is a collection of data organized in tables. There are relations among the tables. The
tables are formally described. They consist of rows and columns. SQL (Structured Query Language) is a
database computer language designed for managing data in relational database management systems. A table
is a set of values that is organized using a model of vertical columns and horizontal rows. The columns are
identified by their names. A schema of a database system is its structure described in a formal language. It
defines the tables, the fields, relationships, views, indexes, procedures, functions, queues, triggers and other
elements. A database row represents a single, implicitly structured data item in a table. It is also called a tuple
or a record. A column is a set of data values of a particular simple type, one for each row of the table. The
columns provide the structure according to which the rows are composed. A field is a single item that exists at
the intersection between one row and one column. A primary key uniquely identifies each record in the table.
A foreign key is a referential constraint between two tables. The foreign key identifies a column or a set of
columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. A
trigger is a procedural code that is automatically executed in response to certain events on a particular table in
a database. A view is a specific look on data in from one or more tables. It can arrange data in some specific
order, higlight or hide some data. A view consists of a stored query accessible as a virtual table composed of the
result set of a query. Unlike ordinary tables a view does not form part of the physical schema. It is a dynamic,
virtual table computed or collated from data in the database. A transaction is an atomic unit of database
operations against the data in one or more databases. The effects of all the SQL statements in a transaction can
be either all committed to the database or all rolled back. An SQL result set is a set of rows from a database,
returned by the SELECT statement. It also contains meta-information about the query such as the column
names, and the types and sizes of each column as well. An index is a data structure that improves the speed of
Tables used
Here we will list all the tables, that are used throughout the tutorial.
Movies database
This is the movies.db database. There are three tables. Actors, Movies and ActorsMovies.
BEGIN TRANSACTION;
COMMIT;
BEGIN TRANSACTION;
COMMIT;
BEGIN TRANSACTION;
CREATE TABLE ActorsMovies(Id integer primary key autoincrement, AId integer, MId
integer);
COMMIT;
Test database
BEGIN TRANSACTION;
CREATE TABLE Cars(Id integer PRIMARY KEY, Name text, Cost integer);
COMMIT;
Cars table.
BEGIN TRANSACTION;
COMMIT;
Orders table.
BEGIN TRANSACTION;
CREATE TABLE Friends(Id integer PRIMARY KEY, Name text UNIQUE NOT NULL,
COMMIT;
Friends table.
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS Customers(CustomerId integer PRIMARY KEY, Name text);
COMMIT;
BEGIN TRANSACTION;
CREATE TABLE Names(Id integer, Name text);
COMMIT;
Names table.
BEGIN TRANSACTION;
CREATE TABLE Books(Id integer PRIMARY KEY, Title text, Author text,
COMMIT;
Books table.