lecture # 6. a class of data models conveys semantic meaning implements databases more...

49
Lecture # 6

Upload: debra-holt

Post on 18-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Lecture # 6

Page 2: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

A class of data models Conveys semantic meaning Implements databases more intelligently Support more sophisticated user

interfaces (SQL queries) Research started in 1970s and early

1980s Other names are data modeling, E/R

modeling, E-modeling

Page 3: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Design methodologies that are based on semantic modeling ideas are often referred to as Top-Down methodologies, because they start at a high level of abstraction with real world constructs or entities and finish at the low level of abstraction represented by a specific concrete database design

Page 4: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Chen in 1976 introduced the E/R model

The E/R model allows us to sketch the design of a database informally.

Designs are pictures called entity-relationship diagrams.

Fairly mechanical ways to convert E/R diagrams to real implementations like relational databases exist.

Page 5: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

RequirementsAnalysis

ConceptualDesign

LogicalDesign

DatabaseBuilding

Operation, Mainte-nance, & Tuning

Requirements Specification

ConceptualModel

RelationalModel

Database

EvolvingDatabase

Natural Language

Informal

Formal

Physical

DBMS-specificDBMS-independent

Page 6: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Requirements Analysis Collect and Analyze the requirements of the users.

Conceptual Design Design a conceptual model (schema), e.g., ER model.

Logical Design Translate the ER model into a relational model

(schema). Normalization

Database Building Build the database and write application programs.

Operation, Maintenance, & Tuning Use, maintain, and “tune” the database.

Page 7: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Most systems development efforts follow a classical Systems Development Life Cycle.

1.  Project Identification - preliminary analysis of needs.

2.  Project Initiation and Planning - identifies possible approaches to solving the business need.

3.  Analysis - identify the functional specifications for the business needs - continue to confirm that the project is feasible.

4.  Logical Design - detailed functional specifications in the form of screen designs, report layout designs, data models, processing rules, etc.

5.  Physical Design - programming, development of physical data structures, redesigning parts of the organization to support the new system.

6.  Implementation - sometimes includes testing or testing may be part of physical design.  Includes a plan to cut over to the new system.

7.  Maintenance - continued modification of the system as the firm's needs change.

Page 8: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

This is the concept that there are different levels or views of the data that the firm uses.

Level 0--Reality.  This is the actual real data that managers use.

Level 1--Conceptual Schema - also called a Conceptual Model. This model is developed during the analysis stage of system development. Typically this is some type of diagramming model of the data and the

relationships among the data.  It is an abstractions of reality to focus on the data the firm uses for specific applications.

Entity-Relationship Diagrams capture overall structure of the organization's data

Level 2--External Schema -- also termed a Logical Model. This model is developed during the design stage and represents the actual

implementation of the conceptual model with a specific DBMS product. This includes table design and the application of rules for Normalization

of data and translating conceptual model into relations.

Level 3--Physical or Internal Schema. This is created during the physical design and implementation phase. It includes the actual storage of data, creation of files that comprise the

database including indexes and other structures

Page 9: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Translate an ER schema into a relational schema. Entity Relationship Attribute Subtype

Normalization To ensure you have a “good” design.

Page 10: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

TOTAL PARTICIPATION OF E2 IN R

CARDINALITY RATIO 1:N FOR E1:E2 IN R

STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R

Symbol

E1 R E2

E1 R E2

R(min,max)

E

N

Page 11: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Requirements of the Company (over) simplified: The company is organized into DEPARTMENTs.

Each department has a name, number and an employee who manages the department.

We keep track of the start date of the department manager.

Each department controls a number of PROJECTs.

Each project has a name, number and is located at a single location.

Page 12: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

We store each EMPLOYEE’s social security number, address, salary, gender, and birthdate.

Each employee works for one department but may work on several projects.

We keep track of the number of hours per week that an employee currently works on each project.

We keep track of each employee’s direct supervisor.

Each employee may have a number of DEPENDENTs.

For each dependent, we keep track of their name, gender, birthdate, and relationship to employee.

Page 13: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces
Page 14: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Employee department

Project

Works ForSupervision

Controls

Dependents

manages

Works-on

Location

NumberName

Hours

Name

RelationshipBdateGender

NameSSN

SalaryName

location

No-EmpAddr

Dependent

1

N

N

M

N

N

1

1

1

DNumber

1

N

Page 15: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Participation constraint (double line for total)

e.g. If N employees work for 1 department, put N on line from employee to works_for and 1 on line from department to works_for

If must work for a department, double line, else single line

Page 16: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

An Entity is something about which we store data for use by managers and workers.  An entity can be either an item found in reality or an abstract concept.

Person:  EMPLOYEE, STUDENT, PATIENT

Place:  CITY, DEPARTMENT

Object:  MACHINE, BUILDING, AUTOMOBILE

Event:  CUSTOMER_ORDER, INVENTORY_RENEWAL

Concept:  ACCOUNT, COURSE, WORK_CENTER

Page 17: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Entities - are specific objects or things in the mini-world that are represented in the database; for example, the EMPLOYEE John Smith, the Research DEPARTMENT, the ProductX PROJECT

Attributes are properties used to describe an entity; for example, an EMPLOYEE entity may have a Name, SSN, Address, gender, BirthDate

A specific entity will have a value for each of its attributes; for example, a specific employee entity may have Name=‘John Smith’, SSN=‘123456789’, Address=‘731 Fondren, Houston, TX’, Gender=‘M’, BirthDate=‘09-JAN-75’

Page 18: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Domain: Possible values for an attribute; for example ‘M’ and ‘F’ for the Gender attribute. What could be possible domain for Location???

Simple: Each entity has a single atomic value for the attribute; for example SSN, Gender and name. IS ADDRESS IS ATOMIC??

Composite: The attribute may be composed of several components; for example, Address (Apt#, House#, Street, City, State, ZipCode, Country) or Name(FirstName, MiddleName, LastName). Composition may form a hierarchy where some components are themselves composite.

Page 19: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Multi-valued: An entity may have multiple values for that attribute; for example, Color of a CAR or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}.

Porject Location

In general, composite and multi-valued attributes may be nested arbitrarily to any number of levels although this is rare. For example, PreviousDegrees of a STUDENT is a composite multi-valued attribute denoted by {PreviousDegrees(College, Year, Degree, Field)}.

Page 20: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Entities with the same basic attributes are grouped or typed into an entity type. For example, the EMPLOYEE entity type or the PROJECT entity type.

An attribute of an entity type for which each entity must have a unique value is called a key attribute of the entity type. For example, SSN of EMPLOYEE.

Page 21: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

A key attribute may be composite. For example, VehicleTagNumber is a key of the CAR entity type with components (Number, State).

An entity type may have more than one key. For example, the CAR entity type may have two keys: VehicleIdentificationNumber (popularly called

VIN) and

VehicleTagNumber (Number, State), also known as license_plate number.

Page 22: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

A relationship relates two or more distinct entities with a specific meaning; for example, EMPLOYEE John Smith works on the ProductX PROJECT or EMPLOYEE Franklin Wong manages the Research DEPARTMENT.

Relationships of the same type are grouped or typed into a relationship type. For example, the WORKS_ON relationship type in which EMPLOYEEs and PROJECTs participate, or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate.

Page 23: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

The degree of a relationship type is the number of participating entity types. Both MANAGES and WORKS_ON are binary relationships.

More than one relationship type can exist with the same participating entity types; for examples, MANAGES and WORKS_FOR are distinct relationships between EMPLOYEE and DEPARTMENT participate.

Page 24: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

EMPLOYEE PROJECTWORKS_ON

EMPLOYEE DEPARTMENTMANAGES

EMPLOYEE DEPARTMENT

MANAGES

WORKS_FOR

Hours

Page 25: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

A relationship can relate two entities of the same entity type ; for example, a SUPERVISION relationship type relates one EMPLOYEE (in the role of supervisee ) to another EMPLOYEE (in the role of supervisor ). This is called a recursive relationship type

A relationship type can have attributes; for example, HoursPerWeek of WORKS_ON; its value for each relationship instance describes the number of hours per week that an EMPLOYEE works on a PROJECT.

Page 26: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Employee Supervision

1

N

Page 27: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Structural constraints on relationships: Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N.

Participation constraint (on each participating entity type): total

(called existence dependency ) or partial.

Page 28: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Constraints on Relationship Types ( Also known as ratio constraints ) Maximum Cardinality

One-to-one (1:1) One-to-many (1:N) or Many-to-one (N:1) Many-to-many

Minimum Cardinality (also called participation constraint or existence dependency constraints)

zero (optional participation, not existence-dependent) one or more (mandatory, existence-dependent)

Page 29: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Structural constraints on relationships: Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N.

Participation constraint (on each participating entity type): total

(called existence dependency ) or partial.

Page 30: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Express the number of entities to which another entity can be associated via a relationship set.

Most useful in describing binary relationship sets.

For a binary relationship set the mapping cardinality must be one of the following types: One to one One to many Many to one Many to many

Page 31: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

One to one One to many

Page 32: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Many to one Many to many

Note: Some elements in A and B may not be mapped to any elements in the other set

Page 33: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set

E.g. participation of loan in borrower is total

every loan must have a customer associated to it via borrower

Partial participation: some entities may not participate in any relationship in the relationship set

E.g. participation of customer in borrower is partial

Page 34: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

What is this?

Page 35: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Specified on each participation of an entity type E in a relationship type R

Specifies that each entity e in E participates in at least min and at most max relationship instances in R

Default(no constraint): min=0, max=n Must have minmax, min0, max 1 Derived from the knowledge of mini-world constraintsExamples: A department has exactly one manager and an employee can

manage at most one department.– Specify (0,1) for participation of EMPLOYEE in MANAGES– Specify (1,1) for participation of DEPARTMENT in MANAGES

An employee can work for exactly one department but a department can have any number of employees.

– Specify (1,1) for participation of EMPLOYEE in WORKS_FOR– Specify (0,n) for participation of DEPARTMENT in

WORKS_FOR

Page 36: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

The (min,max) notation for higher order relationship type constraints

(1,1)(0,1)

(1,N)(1,1)

(exactly)(can)

Page 37: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

The (min,max) notation for higher order relationship type constraints

A Teacher can offer min 1 and max 2 OfferingsA Course may have 1 to 3 Offerings

A Student may enroll in from 1 to 5 Offerings

(1,5)

(1,3)(1,2)

Page 38: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

Relationship types of degree 2 are called binary

Relationship types of degree 3 are called ternary and of degree n are called n-ary

Page 39: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

© The Benjamin/Cummings Publishing Company, Inc. 1994, Elmasri/Navathe, Fundamentals of Database Systems, Second Edition

Page 40: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

SUPPLIER

SName

SUPPLY PROJECT

Quality

PART

PartNo

ProjName

Page 41: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

SUPPLIER

SName

SUPPLY PROJECT

PART

PartNo

ProjName

M N

CAN_SUPPLY USES

M M

N N

Page 42: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

SUPPLIER

SName

SS PROJECT

PART

PartNo

ProjName

1 NSUPPLY

N

Quantity

SPJN 1

SP

N

1

Page 43: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

© The Benjamin/Cummings Publishing Company, Inc. 1994, Elmasri/Navathe, Fundamentals of Database Systems, Second Edition

Page 44: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces
Page 45: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces
Page 46: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

An entity that does not have a key attribute A weak entity must participate in an identifying relationship

type with an owner or identifying entity type Entities are identified by the combination of:

A partial key of the weak entity type The particular entity they are related to in the

identifying entity typeExample: Suppose that a DEPENDENT entity is identified by the

dependent’s first name and birthdate, and the specific EMPLOYEE that the dependent is related to. DEPENDENT is a weak entity type with EMPLOYEE as its identifying entity type via the identifying relationship type DEPENDENT_OF

Page 47: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

A student has a name, which consists of a given name and a family name, and a student ID. Each student is uniquely identified by his/her student ID.

A course has a subject and a course ID and the type of equipment being used for the course. For each course, we want to record the number of students taking that course. A course is uniquely identified by its course ID.

A student can be enrolled in an arbitrary number of courses, and an arbitrary number of students can be enrolled in a course. For each course in which they are enrolled students receive a lab mark and an exam mark.

A course cannot exist if there is no student enrolled in it.

A school is distinguished by the honour's degree that it awards. We also want to record to which faculty a school belongs. A student is registered with at most one school, while a school can have an arbitrary number of students.

Page 48: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

A student is also registered for a year of study. A year of study is identified by a number between 1 and 4. A student is registered for only one year of study, but each year can have many students.

For each member of staff we want to record their name and their room number. A member of staff is identified by the combination of these two pieces of data. Staff are appraised by other staff. A member of staff has no more than one appraiser.

Students can be allocated to a member of staff as their tutor. A student can have no more than one tutor. The tutor and the student agree upon a time slot for regular meetings.

For each year of study, there must be one member of staff who acts as the year tutor. A member of staff can only be responsible for one year of study. Students can be registered for a year of study.

Courses are taught by members of staff. A course can have several teachers, and a staff member can teach several courses.

Page 49: Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces

That’s it for today!!!