Top Banner
App Design for Business Topic: Database Topic Number: 7
25
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 7 database

App Design for Business

Topic: Database

Topic Number: 7

Page 2: Lecture 7 database

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);

Page 3: Lecture 7 database

B4004A L1 3

What is a database?

InputOut

put

Page 4: Lecture 7 database

B4004A L1 4

Different types of Database

Page 5: Lecture 7 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.

Page 6: Lecture 7 database

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.

Page 7: Lecture 7 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.

Page 8: Lecture 7 database

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

Page 9: Lecture 7 database

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.

Page 10: Lecture 7 database

B4004A L1 10

Context Drawing

Page 12: Lecture 7 database

12

An example of database tables together with their relationships

B4004A L1

Source: http://carlibrary.org/CarDatabases.htm

Page 13: Lecture 7 database

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

Page 14: Lecture 7 database

B4004A L1 14

… a closer look at databases …

Page 15: Lecture 7 database

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

Page 16: Lecture 7 database

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

Page 17: Lecture 7 database

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

Page 18: Lecture 7 database

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)

Page 19: Lecture 7 database

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

Page 20: Lecture 7 database

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

Page 21: Lecture 7 database

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.

Page 22: Lecture 7 database

B4004A L1 22

Workshop

• In the workshop for this lecture, you will be viewing a series of tutorials explaining more about SQLite.

Page 23: Lecture 7 database

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

Page 24: Lecture 7 database

End of presentation

© Pearson College 2013

Page 25: Lecture 7 database