presenter: jorge barba · 2019-03-22 · piano player. before we see details on relationships we...

52
Presenter: Jorge Barba

Upload: others

Post on 20-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Presenter:

Jorge Barba

Page 2: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Describe the Relational Data Model componentsModel Entities, Relationships and Attributes

Translate a Data Model Diagram into Schema Data types Learn the mapping of

Attributes to Data TypesEntities to Tables

Relationships to Foreign Keys

Learn SQL SELECT statementUnderstand the Projection, Filtering, Join, and Order

Page 3: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Why Data Modeling?

Target: The System.

Application: To automate data management, to generate reports, to record activity.

Examples: Facebook, Amazon, Oracle E-Business Suite, Nowait.

Databases hold the data, the application is used to enter, modify, remove the data, and generate reports. Together the Database and the Application are “The System”.

Page 4: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Scientific Model

Conceptual Model, Entity Relationship Model, Data Modeling

Conceptual Model vs Physical Model

Business Rules/Business Functionality vs Programs/Applications

Tables and Programs are the target but we start with The Model

Page 5: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

It describes the information needs of the business (Requirements)

It facilitates discussion

It helps to prevent mistakes

Common language between Developers, Designers, DBAs

A model forms a basis for the design of the physical database

Regardless of the final Database destination the Model works for any physical implementation

Page 6: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Out of everything out there in the World

What do I care about to have in … “The System”?

Example: Camera Store

Page 7: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

We want to sell cameras and lenses

Mainly Nikon, Canon, Sony, Fujifilm and some other brands

No bundles, lens sold separately

We will have different technologies from DSLR to Mirrorless to Film

We are interested in comparing features like ISO Sensitivity Range, Top Continuous Speed (FPS), Movie Resolution, Sensor Size, Effective Pixels (Megapixels)

The orders from Customers are archived

We don’t care about accounting, stock control, payroll

Page 8: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Find out the entities for the Camera Store

Page 9: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Out there in the world what interests me for The System

The business wants to keep information about it

An ENTITY is a class or type of things

Entities have instances

An ENTITY is usually a noun

Page 10: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

The attributes DESCRIBE the entity

An attribute is a property of the entity

We are interested only in attributes relevant to “The System”

Attributes have values

An attribute value can be a number, a character string, a date, an image.

Page 11: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Distinction between an ENTITY, an attribute, and an instance of an entity.

Page 12: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Find out the attributes for Camera

Page 13: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional
Page 14: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

How the entities are mutually related

Always exist between two entities

Have two perspectives

Are named at both ends

Page 15: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

RELATIONSHIP EXAMPLESEMPLOYEES have JOBS

JOBS are held by EMPLOYEES

PRODUCTS are classified by a PRODUCT TYPE

PRODUCT TYPE is a classification for a PRODUCT

PEOPLE make TICKET RESERVATIONS

TICKET RESERVATIONS are made by PEOPLE

Page 16: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

All EMPLOYEES have a JOBNo EMPLOYEE has more than one JOB

Not all JOBS are held by an EMPLOYEE

Some JOBS are held by more than one EMPLOYEE

ShintaroJill

AdamAhmed

Maria

ManagerCook

WaitressDish washer

Financial controllerPorter

WaiterPiano player

Page 17: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Before we see details on Relationships we open a parenthesis to see how to represent the model

Page 18: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

* Mandatory attribute

o Optional attribute

EMPLOYEE* Family Name* Addresso Birth Dateo Shoe Sizeo Email

JOB* Title* Description

Attributes in Diagrams

Page 19: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

An employee has exactly one job

EMPLOYEEJOBhas

held by

Mandatory: Optional:

FK

Page 20: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

All EMPLOYEES have a JOBNo EMPLOYEE has more than one JOB

Not all JOBS are held by an EMPLOYEE

Some JOBS are held by more than one EMPLOYEE

ShintaroJill

AdamAhmed

Maria

ManagerCook

WaitressDish washer

Financial controllerPorter

WaiterPiano player

Page 21: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

How do you relate to others?

Do you have good relations?

You Are The Average Of The Five People You Spend The Most Time With

Page 22: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

1:m

(a)

(b)

(c)

(d)

Optional: Mandatory:

Page 23: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

m:m

(e)

(f)

(g)

Optional: Mandatory:

Page 24: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

1:1

(h)

(i)

(j)

Optional: Mandatory:

Page 25: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Group the various types of information into entities and attributes.

Name the relationships and draw a diagram.

Page 26: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Read a relationship.

Page 27: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Use your knowledge of people and towns.

Page 28: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Use your knowledge of shopping.

Page 29: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

m:m

Page 30: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Quantity is an attribute of . . .

Page 31: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Quantity is an attribute of . . .

Page 32: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

New Entity ORDER

FK1 FK2

Page 33: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Multiple PRODUCTS for an ORDER

Page 34: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Another New Entity : ORDER ITEM

Page 35: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Another New Entity : ORDER ITEM becomes the ORDER_ITEMS table

FK1 FK2

FK

Page 36: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

The key to a good model and a good life is GOOD RELATIONS

Page 37: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Read the Relationship

Page 38: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Relationships express how entities are connected.

Initially relationships often seem to be of type m:m.

Finally relationships are most often of type m:1.

Relationships can be resolved into: – Two new relationships. – One intersection entity.

Third Normal form is generally accepted standard.

Page 39: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional
Page 40: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional
Page 41: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

DDL

Page 42: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional
Page 43: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

DML

SELECT

INSERT

UPDATE

DELETE

MERGE

DDL

CREATE

ALTER

DROP

RENAME

TRUNCATE

DCL

GRANT

REVOKE

Transaction Control

COMMIT

ROLLBACK

SAVEPOINT

Page 44: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Using the Order Entry (OE) sample schema

Tables: CUSTOMERS

Page 45: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Using the Order Entry (OE) sample schema

Tables: ORDERS

Page 46: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Using the WHERE clause in the SELECT statement to filter the rows with a condition

Page 47: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Using the WHERE clause in the SELECT statement to filter the rows with two conditions

Page 48: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Using the WHERE clause in the SELECT statement to JOIN two tables and to filterthe rows with two conditions

Page 49: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Using the ORDER BY clause in the SELECT statement to order by order date in descending order (most recent orders first)

Page 50: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Not really

It depends

It is iterative prior to physical phase

Once the structures are built the process does not iterate

Modifications are needed but more like change management not as repetitive iterations

Everyone has its own methodology

Page 51: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional
Page 52: Presenter: Jorge Barba · 2019-03-22 · Piano player. Before we see details on Relationships we open a parenthesis to see how to represent the model * Mandatory attribute o Optional

Data Modeling and Relational Database Design Volume 1 Student Guide – Oracle Corp.

Oracle Database: SQL Fundamentals I Student Guide – Oracle Corp.

Data Modeling and Database Design - Minder Chen, Ph.D.

Database Analysis and ER Modeling: db.grussell.org

DB Design Tutorial: California State University Long Beach, Department of Computer Engineering and Computer Science: web.csulb.edu/colleges/coe/cecs/dbdesign

Web Database Applications with PHP and MySQL: Entity Relationship Modeling docstore.mik.ua/orelly/webprog/webdb/appc_02.htm

Guru 99: https://www.guru99.com/database-normalization.html