SlideShare une entreprise Scribd logo
1  sur  39
TK 2323
MOBILE PROGRAMMING
SEM 2 2016/2017
(STORAGE)
LAM MENG CHUN
lammc@ukm.edu.my
H-04-10
Outline
• SharedPreferences
• SQLite Databse
• Network Connection/Cloud (Firebase)
• Internal Storage (Optional)
• External Storage (Optional)
• Content Provider (Optional)
Database
SQL - Structured Query Language
(http://www.w3schools.com/sql/)
(Optional)
Database
• A collection of systematic data.
• Data
• Name, Age, Height, Weight
• Record
• a table row corresponds to a unit of data
• https://www.youtube.com/watch?v=FR4QIeZaPeM
Database
• Powerful
• Able to search, filter combine data from many sources
• Fast
• Able to search/filter a database very quickly compared to a file
• Big
• Scale well up to very large data sizes
• Safe
• Built-in mechanisms for failure recovery (transactions)
• Multi-user
• Concurrency features let many use view/ edit data at same
time
Database
• Oracle
• Microsoft
• SQL Server
• Access
• MySQL
• Simple free open-source database system
• SQLite
• Transportable, lightweight free open source database system
SQL
• Structured Query Language (SQL):
• SQL is used to communicate with a database
• SQL statements are used to perform tasks such as update
data on a database, or retrieve data from a database
• Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc.
Although most database systems use SQL, most of them
also have their own additional proprietary extensions that
are usually only used on their system.
• However, the standard SQL commands such as "Select",
"Insert", "Update", "Delete", "Create", and "Drop" can be
used to accomplish almost everything that one needs to do
with a database.
The SQL CREATE TABLE
Statement
• Each value stored in an SQLite database (or manipulated by
the database engine) has one of the following storage
classes:
• NULL. The value is a NULL value. (Avoid It)
• INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or
8 bytes depending on the magnitude of the value.
• REAL. The value is a floating point value, stored as an 8-byte
IEEE floating point number.
• TEXT. The value is a text string, stored using the database
encoding (UTF-8, UTF-16BE or UTF-16LE).
• BLOB. The value is a blob of data, stored exactly as it was input.
• A BLOB is a Binary Large Object. It is used to store large
quantities of binary data in a database.
• You can use it to store any kind of binary data that you want,
includes images, video, or any other kind of binary data that
you wish to store.
Boolean Datatype
• SQLite does not have a separate Boolean storage class.
• Instead, Boolean values are stored as integers 0 (false)
and 1 (true).
Date and Time Datatype
The SQL CREATE TABLE
Statement
• CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
• CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
The SQL CREATE TABLE
Statement
• CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
• How to create the table below:
matriNo Name phoneNumber
The SQL SELECT Statement
• SELECT column_name,column_name
FROM table_name;
The SQL SELECT Statement
• SELECT CustomerName, City FROM Customers;
• If want to select the Customer Name, Address and Postal
Code records, how?
The SQL SELECT Statement
• SELECT _________ FROM _____________;
• If want to select the Customer Name, Address and City
records, how?
The SQL SELECT DISTINCT
Statement
• In a table, a column may contain many duplicate values;
• and sometimes you only want to list the different (distinct)
values.
The SQL SELECT DISTINCT
Statement
• SELECT DISTINCT column_name,column_name
FROM table_name;
• SELECT DISTINCT City FROM Customers;
• If we want to know what country customers are come from.
How?
The SQL SELECT DISTINCT
Statement
• SELECT DISTINCT column_name,column_name
FROM table_name;
• SELECT DISTINCT ________FROM ________;
• If we want to know what country customers are come from.
How?
The SQL WHERE Clause
• SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
Operator Description
= Equal
<> Not equal. Note: In some versions of SQL this operator may be
written as !=
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column
The SQL WHERE Clause
• SELECT * FROM Customers
WHERE Country='Mexico';
• SELECT * FROM Customers
WHERE CustomerID=1;
The SQL WHERE Clause
• SELECT __________
FROM ____________
WHERE ______________;
• If we want the information about the customers who come
from London?
The SQL AND & OR Operators
• The AND operator displays a record if both the first
condition AND the second condition are true.
• The OR operator displays a record if either the first
condition OR the second condition is true.
• SELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
The SQL AND & OR Operators
• SELECT * FROM Customers
WHERE Country='Germany'
AND City='Berlin';
The SQL AND & OR Operators
• SELECT * FROM Customers
WHERE City='Berlin'
OR City='München';
The SQL AND & OR Operators
• SELECT * FROM Customers
WHERE Country='Germany'
AND (City='Berlin' OR City='München');
The SQL AND & OR Operators
• If we want the information about the customers who come
from London or Paris
• SELECT * FROM ______
WHERE _________
SQL ORDER BY Keyword
• The ORDER BY keyword is used to sort the result-set by
one or more columns.
• The ORDER BY keyword sorts the records in ascending
order by default. To sort the records in a descending order,
you can use the DESC keyword.
• SELECT column_name, column_name
FROM table_name
ORDER BY
column_name ASC|DESC, column_name ASC|DESC;
SQL ORDER BY Keyword
• SELECT * FROM Customers
ORDER BY Country;
SQL ORDER BY Keyword
• SELECT * FROM Customers
ORDER BY Country DESC;
SQL ORDER BY Keyword
• SELECT * FROM Customers
ORDER BY Country, CustomerName;
SQL INSERT INTO Statement
• The INSERT INTO statement is used to insert new records
in a table.
• It is possible to write the INSERT INTO statement in two
forms.
• The first form does not specify the column names where
the data will be inserted, only their values:
• INSERT INTO table_name
VALUES (value1,value2,value3,...);
• The second form specifies both the column names and the
values to be inserted:
• INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
SQL INSERT INTO Statement
• INSERT INTO Customers (CustomerName, ContactName,
Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen
21','Stavanger','4006','Norway');
SQL INSERT INTO Statement
• It is also possible to only insert data in specific columns.
• INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');
SQL INSERT INTO Statement
• How to insert your own data into the “Customers” table
• Name, Ali
• City, KL
• Country, Malaysia
SQL UPDATE Statement
• The UPDATE statement is used to update records in a
table.
• UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
SQL UPDATE Statement
• UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
Update Warning!
• Be careful when updating records. If we had omitted the
WHERE clause, in the example above, like this:
• UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg';
SQL DELETE Statement
• The DELETE statement is used to delete records in a
table.
• DELETE FROM table_name
WHERE some_column=some_value;
• DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND
ContactName='Maria Anders';
SQL DELETE Statement
• Delete All Data
• DELETE FROM table_name;
or
DELETE * FROM table_name;

Contenu connexe

Tendances

Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLEhsan Hamzei
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slidesenosislearningcom
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLRam Kedem
 
Basic datatypes - deep understanding
Basic datatypes - deep understandingBasic datatypes - deep understanding
Basic datatypes - deep understandingLiron Amitzi
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusChhom Karath
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Beat Signer
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Punjab University
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 

Tendances (20)

Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Sql
SqlSql
Sql
 
Create table
Create tableCreate table
Create table
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Data concepts
Data conceptsData concepts
Data concepts
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
Basic datatypes - deep understanding
Basic datatypes - deep understandingBasic datatypes - deep understanding
Basic datatypes - deep understanding
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Sql commands
Sql commandsSql commands
Sql commands
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 

Similaire à Tk2323 lecture 7 sql

DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptgourav kottawar
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Jennifer Berk
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxYashaswiniSrinivasan1
 
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptxShshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx086ChintanPatel1
 
SQL Assessment Command Statements
SQL Assessment Command StatementsSQL Assessment Command Statements
SQL Assessment Command StatementsShaun Wilson
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSeyed Ibrahim
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptxMohamedNowfeek1
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Salman Memon
 
Lesson-02 (1).pptx
Lesson-02 (1).pptxLesson-02 (1).pptx
Lesson-02 (1).pptxssuserc24e05
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersMichael Rys
 

Similaire à Tk2323 lecture 7 sql (20)

DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptxShshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
Sql introduction
Sql introductionSql introduction
Sql introduction
 
SQL Assessment Command Statements
SQL Assessment Command StatementsSQL Assessment Command Statements
SQL Assessment Command Statements
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
Les09
Les09Les09
Les09
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functions
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
 
Les09.ppt
Les09.pptLes09.ppt
Les09.ppt
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base
 
Lesson-02 (1).pptx
Lesson-02 (1).pptxLesson-02 (1).pptx
Lesson-02 (1).pptx
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
 
SQL
SQLSQL
SQL
 
Access 04
Access 04Access 04
Access 04
 

Plus de MengChun Lam

Tk2323 lecture 10 sensor
Tk2323 lecture 10   sensorTk2323 lecture 10   sensor
Tk2323 lecture 10 sensorMengChun Lam
 
Tk2323 lecture 9 api json
Tk2323 lecture 9   api jsonTk2323 lecture 9   api json
Tk2323 lecture 9 api jsonMengChun Lam
 
Tk2323 lecture 11 process and thread
Tk2323 lecture 11   process and threadTk2323 lecture 11   process and thread
Tk2323 lecture 11 process and threadMengChun Lam
 
Tk2323 lecture 8 firebase
Tk2323 lecture 8   firebaseTk2323 lecture 8   firebase
Tk2323 lecture 8 firebaseMengChun Lam
 
Tk2323 lecture 4 ui ux
Tk2323 lecture 4   ui uxTk2323 lecture 4   ui ux
Tk2323 lecture 4 ui uxMengChun Lam
 
Tk2323 lecture 6 fragment (new)
Tk2323 lecture 6   fragment (new)Tk2323 lecture 6   fragment (new)
Tk2323 lecture 6 fragment (new)MengChun Lam
 
Tk2323 lecture 7 data storage
Tk2323 lecture 7   data storageTk2323 lecture 7   data storage
Tk2323 lecture 7 data storageMengChun Lam
 
Tk2323 lecture 5 material design &amp; recycler view
Tk2323 lecture 5   material design &amp; recycler viewTk2323 lecture 5   material design &amp; recycler view
Tk2323 lecture 5 material design &amp; recycler viewMengChun Lam
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intentMengChun Lam
 
Tk2323 lecture 2 ui
Tk2323 lecture 2   uiTk2323 lecture 2   ui
Tk2323 lecture 2 uiMengChun Lam
 
Tk2323 lecture 1 introduction to mobile application
Tk2323 lecture 1   introduction to mobile applicationTk2323 lecture 1   introduction to mobile application
Tk2323 lecture 1 introduction to mobile applicationMengChun Lam
 

Plus de MengChun Lam (11)

Tk2323 lecture 10 sensor
Tk2323 lecture 10   sensorTk2323 lecture 10   sensor
Tk2323 lecture 10 sensor
 
Tk2323 lecture 9 api json
Tk2323 lecture 9   api jsonTk2323 lecture 9   api json
Tk2323 lecture 9 api json
 
Tk2323 lecture 11 process and thread
Tk2323 lecture 11   process and threadTk2323 lecture 11   process and thread
Tk2323 lecture 11 process and thread
 
Tk2323 lecture 8 firebase
Tk2323 lecture 8   firebaseTk2323 lecture 8   firebase
Tk2323 lecture 8 firebase
 
Tk2323 lecture 4 ui ux
Tk2323 lecture 4   ui uxTk2323 lecture 4   ui ux
Tk2323 lecture 4 ui ux
 
Tk2323 lecture 6 fragment (new)
Tk2323 lecture 6   fragment (new)Tk2323 lecture 6   fragment (new)
Tk2323 lecture 6 fragment (new)
 
Tk2323 lecture 7 data storage
Tk2323 lecture 7   data storageTk2323 lecture 7   data storage
Tk2323 lecture 7 data storage
 
Tk2323 lecture 5 material design &amp; recycler view
Tk2323 lecture 5   material design &amp; recycler viewTk2323 lecture 5   material design &amp; recycler view
Tk2323 lecture 5 material design &amp; recycler view
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intent
 
Tk2323 lecture 2 ui
Tk2323 lecture 2   uiTk2323 lecture 2   ui
Tk2323 lecture 2 ui
 
Tk2323 lecture 1 introduction to mobile application
Tk2323 lecture 1   introduction to mobile applicationTk2323 lecture 1   introduction to mobile application
Tk2323 lecture 1 introduction to mobile application
 

Dernier

Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝soniya singh
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...wyqazy
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Niamh verma
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 

Dernier (8)

Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 

Tk2323 lecture 7 sql

  • 1. TK 2323 MOBILE PROGRAMMING SEM 2 2016/2017 (STORAGE) LAM MENG CHUN lammc@ukm.edu.my H-04-10
  • 2. Outline • SharedPreferences • SQLite Databse • Network Connection/Cloud (Firebase) • Internal Storage (Optional) • External Storage (Optional) • Content Provider (Optional)
  • 3. Database SQL - Structured Query Language (http://www.w3schools.com/sql/) (Optional)
  • 4. Database • A collection of systematic data. • Data • Name, Age, Height, Weight • Record • a table row corresponds to a unit of data • https://www.youtube.com/watch?v=FR4QIeZaPeM
  • 5. Database • Powerful • Able to search, filter combine data from many sources • Fast • Able to search/filter a database very quickly compared to a file • Big • Scale well up to very large data sizes • Safe • Built-in mechanisms for failure recovery (transactions) • Multi-user • Concurrency features let many use view/ edit data at same time
  • 6. Database • Oracle • Microsoft • SQL Server • Access • MySQL • Simple free open-source database system • SQLite • Transportable, lightweight free open source database system
  • 7. SQL • Structured Query Language (SQL): • SQL is used to communicate with a database • SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database • Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc. Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system. • However, the standard SQL commands such as "Select", "Insert", "Update", "Delete", "Create", and "Drop" can be used to accomplish almost everything that one needs to do with a database.
  • 8. The SQL CREATE TABLE Statement • Each value stored in an SQLite database (or manipulated by the database engine) has one of the following storage classes: • NULL. The value is a NULL value. (Avoid It) • INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. • REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number. • TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE). • BLOB. The value is a blob of data, stored exactly as it was input. • A BLOB is a Binary Large Object. It is used to store large quantities of binary data in a database. • You can use it to store any kind of binary data that you want, includes images, video, or any other kind of binary data that you wish to store.
  • 9. Boolean Datatype • SQLite does not have a separate Boolean storage class. • Instead, Boolean values are stored as integers 0 (false) and 1 (true).
  • 10. Date and Time Datatype
  • 11. The SQL CREATE TABLE Statement • CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... ); • CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );
  • 12. The SQL CREATE TABLE Statement • CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... ); • How to create the table below: matriNo Name phoneNumber
  • 13. The SQL SELECT Statement • SELECT column_name,column_name FROM table_name;
  • 14. The SQL SELECT Statement • SELECT CustomerName, City FROM Customers; • If want to select the Customer Name, Address and Postal Code records, how?
  • 15. The SQL SELECT Statement • SELECT _________ FROM _____________; • If want to select the Customer Name, Address and City records, how?
  • 16. The SQL SELECT DISTINCT Statement • In a table, a column may contain many duplicate values; • and sometimes you only want to list the different (distinct) values.
  • 17. The SQL SELECT DISTINCT Statement • SELECT DISTINCT column_name,column_name FROM table_name; • SELECT DISTINCT City FROM Customers; • If we want to know what country customers are come from. How?
  • 18. The SQL SELECT DISTINCT Statement • SELECT DISTINCT column_name,column_name FROM table_name; • SELECT DISTINCT ________FROM ________; • If we want to know what country customers are come from. How?
  • 19. The SQL WHERE Clause • SELECT column_name,column_name FROM table_name WHERE column_name operator value; Operator Description = Equal <> Not equal. Note: In some versions of SQL this operator may be written as != > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern IN To specify multiple possible values for a column
  • 20. The SQL WHERE Clause • SELECT * FROM Customers WHERE Country='Mexico'; • SELECT * FROM Customers WHERE CustomerID=1;
  • 21. The SQL WHERE Clause • SELECT __________ FROM ____________ WHERE ______________; • If we want the information about the customers who come from London?
  • 22. The SQL AND & OR Operators • The AND operator displays a record if both the first condition AND the second condition are true. • The OR operator displays a record if either the first condition OR the second condition is true. • SELECT column_name(s) FROM table_name WHERE condition AND|OR condition
  • 23. The SQL AND & OR Operators • SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';
  • 24. The SQL AND & OR Operators • SELECT * FROM Customers WHERE City='Berlin' OR City='München';
  • 25. The SQL AND & OR Operators • SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');
  • 26. The SQL AND & OR Operators • If we want the information about the customers who come from London or Paris • SELECT * FROM ______ WHERE _________
  • 27. SQL ORDER BY Keyword • The ORDER BY keyword is used to sort the result-set by one or more columns. • The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword. • SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;
  • 28. SQL ORDER BY Keyword • SELECT * FROM Customers ORDER BY Country;
  • 29. SQL ORDER BY Keyword • SELECT * FROM Customers ORDER BY Country DESC;
  • 30. SQL ORDER BY Keyword • SELECT * FROM Customers ORDER BY Country, CustomerName;
  • 31. SQL INSERT INTO Statement • The INSERT INTO statement is used to insert new records in a table. • It is possible to write the INSERT INTO statement in two forms. • The first form does not specify the column names where the data will be inserted, only their values: • INSERT INTO table_name VALUES (value1,value2,value3,...); • The second form specifies both the column names and the values to be inserted: • INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
  • 32. SQL INSERT INTO Statement • INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');
  • 33. SQL INSERT INTO Statement • It is also possible to only insert data in specific columns. • INSERT INTO Customers (CustomerName, City, Country) VALUES ('Cardinal', 'Stavanger', 'Norway');
  • 34. SQL INSERT INTO Statement • How to insert your own data into the “Customers” table • Name, Ali • City, KL • Country, Malaysia
  • 35. SQL UPDATE Statement • The UPDATE statement is used to update records in a table. • UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;
  • 36. SQL UPDATE Statement • UPDATE Customers SET ContactName='Alfred Schmidt', City='Hamburg' WHERE CustomerName='Alfreds Futterkiste';
  • 37. Update Warning! • Be careful when updating records. If we had omitted the WHERE clause, in the example above, like this: • UPDATE Customers SET ContactName='Alfred Schmidt', City='Hamburg';
  • 38. SQL DELETE Statement • The DELETE statement is used to delete records in a table. • DELETE FROM table_name WHERE some_column=some_value; • DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders';
  • 39. SQL DELETE Statement • Delete All Data • DELETE FROM table_name; or DELETE * FROM table_name;