In and Out in Sqlite
In and Out in Sqlite
A ND e
IN SQLi t
IN
Introduction
Understanding the basics oF sQLite is
essential for developing Android
applications because it provides a robust
and efficient way to manage local data
storage . SsQLite is integrated into the
Android operating system to create, read,
update, and delete data in a relational
database with minimal overhead. Its
lightweight, serverless architecture makes
it perfect for mobile environments where
resources are limited.
Data Defi nition
Language (DDL)
• CREATE TABLE: The 'CREATE TABLE' statement is used to
create a new table in the database. It defines the structure of
the table, including the names of the columns, their data
types, and any constraints on the columns.
• Example: To create a table named 'employees': CREATE
TABLE employees ( id INTEGER PRIMARY KEY, name text not
NULL, position
• ALTER TEXT salary REAL CHECK(salary > 0)
TABLE: The 'ALTER TABLE' statement is used to);
modify the structure of an existing table. It can be used to
add, remove, or rename columns in a table.
• Example: To add a new column named 'hire_date' to the
‘employees' table:
ALTER TABLE employees ADD COLUMN hire_date TEXT;
• DROP TABLE: The 'DROP TABLE’ statement is
used to delete an existing table from he
database. This statement permanently removes
the table and all of its data, so it should be used
with caution.
• Example: To delete the 'employees' table if it
exists:
DROP TABLE IF EXISTS employees;
Constraints
• PRIMARY KEY:A primary key constraint
uniquely identifies each row in the table.
Primary keys must contain unique values
and cannot be null.
• Example: id INTEGER PRIMARY KEY Ensures that
the 'id' column uniquely identifies each row.
• NOT NULL:A NOT NULL constraint ensures
that a column cannot have a null value.
• Example: name TEXT NOT NULL Ensures that the
'name' column cannot contain null values.
• UNIQUE:A UNIQUE constraint ensures that
all values in a column are unique.
• Example: email TEXT UNIQUE Ensures that all
values in the 'email' column are unique.
• CHECK:A CHECK constraint ensures that all
values in a column satisfy a specific condition.
• Example: salary REAL CHECK(salary > 0)
Ensures that the 'salary' column contains only
positive values.