1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability,...

49
1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity, Barred relationship, CRUD analysis

Transcript of 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability,...

Page 1: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

1

Database Design

Sections 4 & 5Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity, Barred relationship, CRUD analysis

Page 2: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

2

DJs on Demand – Partial ERD

Page 3: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

3

Reserved Words

A reserved work is one that has a specific meaning and function in the computer system, language, or database.

Examples: NULL DATE DISTINCT

Page 4: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

4

Video Store – example next slide

Identify business rules Construct ERD Class activity

Page 5: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

5

Video Store example

Read the given business scenario and walk through the steps below.

1. Examine the nouns. Are they things of significance?

2. Name each entity.

3. Is there information of interest about the entity that the business needs to hold?

4. Is each instance of the entity uniquely identifiable? Which attribute or attributes could serve as its UID?

5. Write a description of the entity.

6. Diagram each entity and a few of its attributes.  Remember, entity names are always singular.

7. Identify the relationships and draw them on the ERD.

Page 6: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

6

Video ERD

featured in

•TAPE/DVDnumberformat

MOVIEid

titlecategory

ACTORstage namereal name

CUSTOMERmembership

numberlast namefirst name

phone number

a copy of

on

the feature ofrented by

the renter of

Page 7: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

7

Use Source Documents

Source document assist in identifying entities, attributes, and relationships

Page 8: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

8

Subtype

A subtype: inherits all attributes of the supertype inherits all relationships of the supertype usually has its own attributes or

relationships is drawn within the supertype never exists alone may have subtypes of its own is also known as a "subentity“

Page 9: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

9

Subtype & Supertype

Supertype (entity) can be subdivided into Subtypes

Example:

JOBmanager

clerksales

support

Page 10: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

10

Attributes

Supertype can have attributes at supertype level

Attributes at supertype level are for all subtypes

Subtypes can have own attributes for only that attribute

Page 11: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

11

Example

EXAM#number

*description*weight*date

*grade for written component

MIDTERM*grade for

oral presentation

FINAL*extra pts for opt. paper

QUIZ

BONUS QUESTIONS

STUDENT

included in

include

taken by

takes

Page 12: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

12

Global Fast Food Employees STAFF is an entity with supertypes What are the attributes of STAFF?

#id *first name *last name *DOB *salary

What subtypes exist in STAFF? ORDER TAKER *overtime COOK *training OTHER

Are there any attributes in any of the subtypes?

Page 13: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

13

Example: an incorrect subtypes in the illustration.

AUTOMOBILE subtypes are not mutually exclusive

AUTOMOBILE possible solution

BUILDING subtypes have problem of not being exhaustive, should be minimum of 2 types

Page 14: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

14

Subtype Needs Exhaustive:

Every instance of the supertype is also an instance of one of the subtypes.

Treating all parts or aspects without omissions. 2 or more items

Mutually exclusive: Every instance of the supertype is of one and

only one subtype. A relationship that presents choices which are

unable to be true at the same time.

Page 15: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

15

Correctly identify subtypes

When considering supertypes and subtypes, you can use three questions to see if the subtype is correctly identified:1. Is this subtype a kind of supertype?2. Have I covered all possible cases?

(exhaustive)3. Does the example fit into one and only

one subtype? (mutually exclusive)

Page 16: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

16

Nested subtypes

Page 17: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

17

Documenting Business Rules

Source documents assist in identiying: entities attributes relationships Some business rules are “implemented

by programming”

Page 18: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

18

Business Rules Recognize if Business rule is implemented

by the data model or by programming Example:

Only an employee with a title of manager can manage other employees

The event planner must contact the customer before the DJ can be assigned

Business rules can be changed as society changes or business leaders feel change is needed

Page 19: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

19

Business rule types Structural

Must be entered at time of initial data entry Example: When ORDER entered a staff id must

be entered Does not require code written to enforce

Procedural Work flow related Programmed validation is procedural constraint

Generally need to write code Example: Commission can not be > 25% of

salary

Page 20: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

20

Structural Business Rule examples:

Page 21: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

21

Procedural Business Rule example:

Page 22: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

22

Discussion Students must have studied algebra and

geometry in order to sign up for trigonometry. Could you represent this in the ERD?

• How would you implement this with programming?

• If the student had taken the subjects, can you think of an additional business rule that a school may want in this scenario?

Page 23: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

23

Each entity has

Name Optionality Cardinality Transferability

Example on next slide.

Page 24: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

24

Relationship Transferability

Page 25: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

25

Relationship transferability Rules established for the purpose such as

safety, efficiency, or increased profit Example: Airline tickets

can be transferable or non-transferable?

Non-transferable means also not updatable symbol used to denote non-

transferable blood type is non-transferable

Page 26: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

26

Non-transferable relationship

Orders are non-transferable Resolution would be to cancel order

and create new order

CUSTOMER ORDER

place

placed by

Page 27: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

27

Example 5.1 exercise 1 a

Each town may be the birthplace of many people. Each person must be born in one and only one town.

PERSON TOWNbirthplace for

born in

Page 28: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

28

Relationship types

One to One (1:1) One to Many (1:M) Many to Many (M:M)

Page 29: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

29

One to One relationship

Page 30: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

30

One to One relationship

Usually few of these relationships Often mandatory at one side If mandatory at both ends be aware,

it might be a error. Possible should be only one entity not two

PERSON BYCYCLE

ride

ridden by

Page 31: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

31

One to One relationship

Page 32: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

32

One to Many relationship

Page 33: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

33

One to Many

Most common type are mandatory on one side and optional on the other

Mandatory at both ends models entities that cannot exist without each other

ORDERORDER TYPE

Page 34: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

34

One to Many example

TAX RETURNTAX REPORT

LINE

BAND MUSICIANcomposed of

belong to

composed of

entered in

Page 35: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

35

Many to Many relationship

Page 36: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

36

Many to Many

Often common in initial version of ERD

Later stage of design converted to other type

STUDENT TEACHERlearn from

educate

Page 37: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

37

Redundant relationship

Redundant relationship is one that can be derived from another relationship in the model

Page 38: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

38

Many to Many Relationship Resolution

All M:M relationships must be changed to a set of 1:M and M:1 relationship

Insert a transition entity between Occurs when you go from conceptual

model to design model

Page 39: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

39

Example: M:M with Intersection Entity

STUDENT COURSE

REGISTRATION

Page 40: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

40

Resolving M:M with Intersection

Create an intersection entity If you can’t find a good intersection

entity create one by concatenate two entities together

Page 41: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

41

Example

PARTNER EVENT

WORK ASSIGNMENT (PARTNER_EVENT)

Page 42: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

42

CRUD analysis

Create ER models that reflect all business rules gathered during the interview process Identify the create, retrieve, update, and

delete (CRUD) requirements of the business

Validate your ER model by performing a CRUD analysis

Page 43: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

43

CRUD requirements CRUD analysis will help you:

Translate between the consultant and the client. Provide a guideline for the DBA who will

eventually build the database. Check that you haven’t missed any entities or

relationships in your data model. Check to make sure that you haven’t modeled

anything that the business does not require.

Page 44: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

44

What is CRUD?

CRUD is an acronym for create, retrieve, update, delete.

Check for completeness and accuracy.

Page 45: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

45

Create keywords

Look for these words when you interview the client.

INPUT ENTER LOAD IMPORT RECORD CREATE

Page 46: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

46

Retrieve keywords Look for: VIEW REPORT BRING UP PRINT FIND READ LOOK UP

Page 47: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

47

Update keywords

Look for: CHANGE MODIFY ALTER UPDATE

Page 48: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

48

Delete keywords

Look for: DISCARD REMOVE TRASH PURGE DELETE

Page 49: 1 Database Design Sections 4 & 5 Subtype, Supertype, Mutually exclusive, non-transferability, transferable, 1:1, 1:M, M:M, Redundant, Intersection entity,

49

CRUD analysis

If you have a business function that has no entity to CRUD against, then your data model may be incomplete. Similarly, if you have entities in your ERD that are not touched by any CRUD (there is no business function that creates, retrieves, updates, or deletes from it), then you may not need that entity in your model.