0% found this document useful (0 votes)
8 views11 pages

In and Out in Sqlite

The document provides an overview of SQLite, emphasizing its importance for Android app development due to its lightweight and efficient data management capabilities. It covers key SQL commands for Data Definition Language (DDL) and Data Manipulation Language (DML), including creating, altering, and deleting tables, as well as inserting, updating, and deleting data. Additionally, it explains various constraints and query statements to manage and retrieve data effectively.

Uploaded by

harshithamangesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

In and Out in Sqlite

The document provides an overview of SQLite, emphasizing its importance for Android app development due to its lightweight and efficient data management capabilities. It covers key SQL commands for Data Definition Language (DDL) and Data Manipulation Language (DML), including creating, altering, and deleting tables, as well as inserting, updating, and deleting data. Additionally, it explains various constraints and query statements to manage and retrieve data effectively.

Uploaded by

harshithamangesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

OU T

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.

• FOREIGN KEY:A FOREIGN KEY constraint


ensures that the value in a column matches
a value in another table, establishing a
relationship between the two tables.
• Example: FOREIGN KEY (department_id )
REFERENCES departments (id) Ensures that
the value in the 'department_id' column
matches a value in the 'id' column of the
'departments' table.
Data Manipulation
Language (DML)
• INsSERT: The 'INSERT' statement is used
to add new rows to a table. It specifies
the table name, the columns to insert
data into, and the corresponding values.
This operation adds new data to the
database.
• Example: INSERT INTO employees (name,
• UPDATE: The 'UPDATE' statement
position, salary) VALUES ('Swati', ' is used
to modify existing
Developer', 60000 ); rows in a table. It
specifies the table name, the columns to
update with new values, and a condition to
determine which rows should be updated.
This operation changes existing data in
the database.

• DELETE: The 'DELETE' statement is used
to remove rows from a table. It specifies
the table name and a condition to
determine which rows should be deleted.
This operation removes data from the
database.
• Example: DELETE FROM employees WHERE
name = 'Swati';
QUERY STATEMENT
(SELECT STATEMENT)

• SELECT: Retrieves specific data from one or


more tables.
• Example: SELECT name, position FROM
employees WHERE salary > 50000 ORDER
BY name LIMIT 10;
• JOIN: Combines rows from two or more
tables based on a related column.
• SELECT employees.name,
departments.name AS department FROM
employees J0IN departments ON
employees.department_id =
departments.id;
• GROUP BY: Arranges identical data into
groups.
• Example: SELECT department_id,
C0UNT(*) FROM employees GROUP BY
department id;
• HAVING: Filters groups based on a
condition, often used with 'GROUP BY'.
• Example: SELECT department_id,
AVG(salary) FROM employees GROUP BY
department_id HAVING AVG(salary) >
50000;
h a n k
T u
Yo

You might also like