47
1 Engineering and Technology Management Data Modeling and ERD

Data Modeling

  • Upload
    canhiz

  • View
    14

  • Download
    2

Embed Size (px)

DESCRIPTION

Data Modelling ETM

Citation preview

Page 1: Data Modeling

1Engineering and Technology Management

Data Modeling and ERD

Page 2: Data Modeling

2Engineering and Technology Management

Business rules

are derived from policies, procedures, events, functions, and other business objects, and state constraints on the organization.

govern how data are handled and stored.

govern creating, updating, and removing data in an information processing and storage system.

ABusiness rule is a statement that defines or constraints some aspects of the business.

Page 3: Data Modeling

3Engineering and Technology Management

Examples

“Every student in the university must have a faculty advisor.”

“A student may register for a section of a course only if s/he has successfully completed the prerequisities for that course.”

“A preferred customer qualifies for a 10 percent discount, unless he has an overdue account balance.”

Page 4: Data Modeling

4Engineering and Technology Management

Business rules

Assert business structure Control/influence business behavior Expressed in terms familiar to end users Automated through DBMS software

Page 5: Data Modeling

5Engineering and Technology Management

Declarative – what, not how Precise – clear, agreed-upon meaning Atomic – one statement Consistent – internally and externally Expressible – structured, natural language Distinct – non-redundant Business-oriented – understood by business

people

Business rules

Page 6: Data Modeling

6Engineering and Technology Management

First proposed by Chen 1976 Several times expanded Different notations available, most notably

Chen originalCrow foot

Entity-Relationship Model

Page 7: Data Modeling

7Engineering and Technology Management

Model is always a simplified depiction of reality Modeling always has a certain purpose

What might be important in one context might be uninteresting in another one

In creating a model, we are abstracting from the full complexity of real life We need to decide on which facts and relations to

keep, and which special cases to strip away

Models and Modeling

Page 8: Data Modeling

8Engineering and Technology Management

E-R model constructs

Entity Type – collection of entities that share common properties or characteristics (often corresponds to a table) Entity instance – a single occurence of an entity type

(often corresponds to a row in a table)

Attribute - property or characteristic of an entity type that is of interest to the organization (often corresponds to a field in a table)

Relationship type – link (association) between entity types (corresponds to primary key-foreign key equivalencies in related tables)

Relationship instance – association between entity instances

Page 9: Data Modeling

9Engineering and Technology Management

Sample E-R diagram

Page 10: Data Modeling

10Engineering and Technology Management

Entity symbols

Relationship symbols

Attribute symbols

A special entity that is also a relationship

Basic E-R notation

Page 11: Data Modeling

11Engineering and Technology Management

Entities

Person: EMPLOYEE, STUDENT, PATIENT

Place: STORE, WAREHOUSE, STATE

Object: MACHINE, BUILDING, AUTOMOBILE

Event: SALE, REGISTRATION, RENEWAL,

RETURN

Concept: ACCOUNT, COURSE, WORK CENTER

Page 12: Data Modeling

12Engineering and Technology Management

What should an entity be?

SHOULD BE: An object that will have many instances in the

database An object that will be composed of multiple

attributes An object that we are trying to model

SHOULD NOT BE: A user of the database system An output of the database system (e.g. a report)

Page 13: Data Modeling

13Engineering and Technology Management

Inappropriate entities

System userSystem user System outputSystem output

Appropriate entities

Page 14: Data Modeling

14Engineering and Technology Management

Entities

Exercise Identify possible entities in the following description. An Airline company wants to store and manage their

data on flights. They own several airplanes, each with a certain number of seats, and have a number of employees. Also they have customers in their frequent flyer program, each has a certain mileage in his/her account. The planes are assigned to certain flights, as well as employees, and customers can buy seats on the flights. Each flight has a destination, a time and date, and a number of miles.

Page 15: Data Modeling

15Engineering and Technology Management

Attributes

Attribute - property or characteristic of an entity type

Classifications of attributes: Simple versus Composite Attribute Single-Valued versus Multivalued Attribute Stored versus Derived Attributes Identifier Attributes

Page 16: Data Modeling

16Engineering and Technology Management

Identifiers (Keys)

Identifier (Key) - An attribute (or combination of attributes) that uniquely identifies individual instances of an entity type

Simple Key versus Composite Key Candidate Key – an attribute that could be a

key…satisfies the requirements for being a key

Page 17: Data Modeling

17Engineering and Technology Management

Characteristics of identifiers

Will not change in value Will not be null No intelligent identifiers (e.g. containing

locations or people that might change) Substitute new, simple keys for long,

composite keys

Page 18: Data Modeling

18Engineering and Technology Management

An attribute broken into component parts

A composite attribute

Page 19: Data Modeling

19Engineering and Technology Management

The key is underlined

Simple key attribute

Page 20: Data Modeling

20Engineering and Technology Management

The key is composed of two subparts

Composite key attribute

Page 21: Data Modeling

21Engineering and Technology Management

Entity with a multivalued attribute (Skill) and derived attribute (Years_Employed)

Derived from date employed and current date

Multivalued: an employee can have more than one skill

Page 22: Data Modeling

22Engineering and Technology Management

An attribute that is both multivalued and composite

Page 23: Data Modeling

23Engineering and Technology Management

Attributes

Exercise Identify possible attributes in the example from last

exercise. Find additional possible attributes. Decide on which attributes would be multi-valued, and which would be candidate keys.

An Airline company wants to store and manage their data on flights. They own several airplanes, each with a certain number of seats, and have a number of employees. Also they have customers in their frequent flyer program, each has a certain mileage in his/her account. The planes are assigned to certain flights, as well as employees, and customers can buy seats on the flights. Each flight has a destination, a time and date, and a number of miles.

Page 24: Data Modeling

24Engineering and Technology Management

Relationships

Relationship Types vs. Relationship Instances The relationship type is modeled as the diamond and

lines between entity types…the instance is between specific entity instances

Relationships can have attributes These describe features pertaining to the association

between the entities in the relationship Two entities can have more than one type of

relationship between them (multiple relationships)

Page 25: Data Modeling

25Engineering and Technology Management

Degree of relationships

Degree of a Relationship is the number of entity types that participate in it

Unary Relationship Binary Relationship Ternary Relationship

Page 26: Data Modeling

26Engineering and Technology Management

One entity related to another of the same entity type

Entities of two different types related to each other

Entities of three different types related to each other

Degree of relationships

Page 27: Data Modeling

27Engineering and Technology Management

Unary relationships

Page 28: Data Modeling

28Engineering and Technology Management

Binary relationships

Page 29: Data Modeling

29Engineering and Technology Management

Note: a relationship can have attributes of its own

Ternary relationships

Page 30: Data Modeling

30Engineering and Technology Management

Cardinality of relationships

One – to – One Each entity in the relationship will have exactly one

related entity One – to – Many

An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity

Many – to – Many Entities on both sides of the relationship can have

many related entities on the other side

Page 31: Data Modeling

31Engineering and Technology Management

Cardinality constraints

Cardinality Constraints - the number of instances of one entity that can or must be associated with each instance of another entity.

Minimum Cardinality If zero, then optional If one or more, then mandatory

Maximum Cardinality The maximum number

Page 32: Data Modeling

32Engineering and Technology Management

Cardinality

Page 33: Data Modeling

33Engineering and Technology Management

Basic relationship with only maximum cardinalities showing

Mandatory minimum cardinalities

Page 34: Data Modeling

34Engineering and Technology Management

Optional cardinalities with unary degree, one-to-one relationship

Page 35: Data Modeling

35Engineering and Technology Management

Relationship type

Entity and Relationship instances

Page 36: Data Modeling

36Engineering and Technology Management

A binary relationship with an attribute

Here, the date completed attribute pertains specifically to the employee’s completion of a course…it is an attribute of the relationship.

Page 37: Data Modeling

37Engineering and Technology Management

A ternary relationship with attributes

Page 38: Data Modeling

38Engineering and Technology Management

Representing a bill­of­materials structure

A unary relationship with an attribute. This has a many-to-many relationship

Page 39: Data Modeling

39Engineering and Technology Management

Examples of multiple relationships – entities can be related to one another in more than one way

Employees and departments

Page 40: Data Modeling

40Engineering and Technology Management

Professors and courses (fixed upon constraint)

Here,max cardinality constraint is 4

Page 41: Data Modeling

41Engineering and Technology Management

Cardinalities

Exercise Find the right cardinalities...

Student

Id Name

Coursetakes

Professor

advises

Textbook

uses

Grade

Page 42: Data Modeling

42Engineering and Technology Management

Cardinalities

Exercise Infer the business rule difference(s) to Bogazici.

What does the first company not support compared to the second one?

CourseProfessor gives

ProductCustomer buys

DateDate Invoice

ProductCustomer buys

Invoice

Page 43: Data Modeling

43Engineering and Technology Management

Strong vs. Weak Entities, andidentifying relationships

Strong entities exist independently of other types of entities has its own unique identifier represented with single-line rectangle

Weak entity dependent on a strong entity…cannot exist on its own does not have a unique identifier represented with double-line rectangle

Identifying relationship links strong entities to weak entities represented with double line diamond

Page 44: Data Modeling

44Engineering and Technology Management

Strong and weak entities

Strong entity Weak entityIdentifying relationship

Page 45: Data Modeling

45Engineering and Technology Management

Supertype / Subtype and Subset

Supertype / Subtype Implements generalisation All attributes of Supertype pertain to Subtypes Normally split on one attribute

Subset Similar, but non-excluse One entity instance can belong to more than one class

Page 46: Data Modeling

46Engineering and Technology Management

Supertype/subtype relationships

Page 47: Data Modeling

47Engineering and Technology Management

ERD

Exercise Model the following situation using ERD. Include

appropriate attributes. A consulting company maintains offices in several

countries. Each office can have several employees assigned, each employee is assigned to one office. Customers offer projects to the company, each project is from one customer. Employees work on the project for a given time and intensity, and can work on more than one project at the same time. A project will have several employees assigned. Each employee has a list of skills. An employee can be either a senior or junior consultant (who has a date for promotion set), a senior one manages several junior one, each junior is assigned to one senior. For each project, there can be several invoices with different amounts and dates.