App Design for Business Topic: Database Topic Number: 7
Jun 20, 2015
App Design for Business
Topic: Database
Topic Number: 7
2
Key topics / learning outcomes of this lecture
• Database use within an Android App;• Learn the concept of creating an
SQLite Database;• A look at SQL (Structured Query
Language);
B4004A L1 3
What is a database?
InputOut
put
B4004A L1 4
Different types of Database
B4004A L1 5
Android Database
The database used with Android is calledSQLite.
This database is a trimmed downversion of MySQL, PostgreSQL and other similar databases.
B4004A L1 6
SqLite Android Database
• it is a relational database;• SQLite was originally designed for defence purposes;• it has no administrator;• it uses less data types than other typical relational
databases:– int: a signed integer;– real: a floating-point number;– text: a text string;– blob: a ‘blob’ of data;
• It is ‘shipped’ with Android:– Each APP has its own SQLite database.
B4004A L1 7
Usual steps to design a database
• Create a Data dictionary– List all the data terms,• example: name, address, postcode;
– Allocate a data type to the field• example: the _id field has a data type of int;
• Create an Input/Output list– identify all inputs and outputs, • example: input name, address, postcode• example: output list of all address in postcode W1.
B4004A L1 8
Usual steps to design a database• Identify Entities
– list relationships• one to one• one to many• many to many
• List attributes– their data type;– their default value;
• Normalize– reduce duplication of data storage
• create new tables to reduce duplication of fields;
• Add keys– primary key– foreign keys
B4004A L1 9
Data Flow Diagrams
• Once all the information gathering is complete, a database design is moved on to the drawing stage;
• The first drawing will be very concise, almost like a ‘birds eye view’ of the database, usually named a Context drawing;
• Each section of the Context drawing will be expanded level by level until the detail is exhausted, therefore no more detailed level may be reached.
B4004A L1 10
Context Drawing
B4004A L1 11
An Example of a Data Flow Diagram
Source: http://conta11.my3gb.com/examlpe-of-data-flow-diagram.html
12
An example of database tables together with their relationships
B4004A L1
Source: http://carlibrary.org/CarDatabases.htm
B4004A L1 13
Databases comprise of …
• Tables– Usually a database will contain more than one
table:– example PERSON, PERSON_ADDRESS.
• Fields– Fields are ‘table columns’ with a heading and
column content• Records – are ‘table rows’ with an ‘id’ and row content
B4004A L1 14
… a closer look at databases …
B4004A L1 15
A table within a Database
_id Name Password
1 Pearson 123
2 John abcd
3 Viz 5678
This table will have a name, for example:
PERSON
This database will have a name, for example:
ADDRESS_BOOK
B4004A L1 16
Relational Tables
address_id Address _id
1 1 Smith Street 2
2 80 Strand 13 6 Jones Square 3
_id Name Password
1 Pearson 123
2 John abcd
3 Viz 5678
This table will have a name, for example:
PERSON
This table will have a name, for
example: PERSON_ADDRESS
B4004A L1 17
Relational Tables
address_id
Address Address_Type _id
1 1 Smith Street Halls of Residence 2
2 80 Strand Office 13 6 Jones Square Private Rented 34 2 The Farmhouse Home 2
_id Name Password
1 Pearson 123
2 John abcd
3 Viz 5678
This table will have a name, for example:
PERSON
This table will have a name, for
example: PERSON_ADDRESS
B4004A L1 18
Relational Tables
address_id
Address Address_Type _id
1 1 Smith Street Halls of Residence 2
2 80 Strand Office 13 6 Jones Square Private Rented 34 2 The Farmhouse Home 2
_id Name Password
1 Pearson 123
2 John abcd
3 Viz 5678
Foreign Key
Primary Key
Fields (Columns)
Records(Rows)
B4004A L1 19
Use SQL to access data, for example
SELECT * FROM PERSON INNER JOIN PERSON_ADDRESS ON PERSON._id = PERSON_ADDRESS._id WHERE PERSON.Name=John;
SELECT column_name(s)FROM table1INNER JOIN table2ON table1.column_name=table2.column_nameWHERE table1.column_name= ? ;
SQL Syntax
Actual SQL derived from the syntax
B4004A L1 20
More SQL (Structured Query Language) Resources
• SQL is a standard database protocol:– adopted by most ‘relational’ databases;
• Provides syntax for interaction with databases;• For more info, visit W3schools for their
tutorial on SQL:– here you will find all the SQL syntax needed to
interact with your database.http://www.w3schools.com/sql
B4004A L1 21
Seminar
• In the seminar for this lecture, you will be copying and pasting code into IntelliJ and running a database.
• You will be making some changes to the fields and tables to learn how you may tailor the database to suit a different application.
B4004A L1 22
Workshop
• In the workshop for this lecture, you will be viewing a series of tutorials explaining more about SQLite.
23
Essential work for next week
• Please consult the OLE for details of:– Essential readings*– Seminar/workshop preparation work*– Recommended further readings– Any additional learning
* Essential readings and preparation work must always be completed in time for the next session
End of presentation
© Pearson College 2013