SQLite Tutorial For Beginners
SQLite Tutorial For Beginners
NULL value.
INTEGER is a signed 64 bit numeric value. SQLite optimizes the
storage of small integers by itself, which is why it is stored in 1, 2, 3, 4, 6,
or 8 bytes depending on the magnitude of the integer value.
REAL is a 64 bit floating point value.
TEXT is a text string, which is stored using database encoding such
as UTF-8.
BLOB is a blob of data, which is stored as direct input. Both Text and
BLOB have default size of 1,000,000,000 bytes.
SQLite uses the concept of type affinity on columns of a table that reduces the
compatibility issues with other database engines. Any column can store any
type of data, but the recommended storage class for a column is called its
affinity. These type affinities are TEXT, NUMERIC, INTEGER, REAL and
NONE. The following is the details of the data types that are used to create
the database table and their affinities.
From the above list of affinities, it is clear that there is no specified data type
available for date-time in SQLite, but by default, these values are saved as
numeric data (number of seconds since the Jan 01, 1970 midnight).
Sometimes, a text string is also used to save the date-time. Same goes for a
Boolean where true and false are stored as 1 and 0 respectively in a column.
SQLite CRUD Statement
SQLite statements start with keywords such as CREATE, INSERT, UPDATE,
DELETE, SELECT, ALTER, DROP, etc. and is case insensitive. CRUD (Create,
Read, Update and Delete) are commonly used operations in every database
engine.
The CREATE statement is used to create new tables in SQLite database. Basic
syntax and a simple example of CREATE TABLE are as follow.
Create Table Statement Syntax:
CREATE TABLE DATABASE_NAME. TABLE_NAME (
column1 datatype,
column2 datatype,
columnN datatype,
PRIMARY KEY (one or more columns)
);
Create EMPLOYEE Table:
sqlite3> CREATE TABLE COMPANY.EMPLOYEE (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
3