Sei sulla pagina 1di 53

1: Database Systems

Part II: Data Modeling

Introduction

In designing databases, we begin by examining the entities that are of importance to an organization. A conceptual data model is created to capture the overall structure of the entities and the relationships among them

Conceptual Data Model

A graphical model showing the following


Characteristics of the entities Relationships among the entities How the database will be physically stored The data model used to implement the database The type of DBMS to be used
3

Independent of :

Entity-Relationship Diagram (ERD)

Most commonly used conceptual model Consists of:

Entities Relationships among entities Attributes of both the entities and their relationships

Entity

An entity is a person, place, thing, or event which an organization wishes to maintain data about Examples:

An entity is represented by a rectangle

STUDENT

Student Subject Instructor

SUBJECT

Entity Type vs. Entity Instance

Entity type

A collection of all occurrences of a given type of entity Also known as entity class
A single occurrence of an entity type An entity type can have many instances

Entity instance

Attributes

An attribute is a characteristic of an entity Sample attributes of the STUDENT entity


An attribute is represented by an ellipse


ID_Num

Name

Name ID Number Address Birthday

STUDENT

Address

Birthday
7

Value of an Attribute

The value of the type of characteristic that an attribute represents Example:

Attribute: Name Values:


Fox Mulder Dana Scully

The ERD contains only the attribute type and not its values
8

Comparison of Attribute Types

Multivalued vs. single-valued Composite vs. simple (or atomic) Derived vs. stored

Multivalued Attributes

Attributes having more than one value for each entity instance Example:

A multivalued attribute is represented by a double ellipse


Hobby STUDENT

Hobby - a student may have more than one hobbies

10

Composite Attributes

An attribute broken into component parts

11

Example: An Attribute Both Multivalued and Composite

12

Derived Attribute

An attributes whose values can be calculated from related attribute values

Derived
from date employed and current date
13

Identification of Entity Instances

The relational model uses primary keys to link related entities together Primary key - an attribute or a combination of attributes that uniquely identifies an instance of an entity Represented by underlining the attribute(s) involved
ID_Num
14

Characteristics of a Primary Key

Unique - no two entity instances can have the same value for the primary key attribute Not null Must not change over time Avoid use of intelligent keys Substitute new, simple keys for long, composite keys
15

Relationship

A relationship is a natural association between the instances of one or more entities Example:

A relationship is represented by a diamond-shaped symbol

enrolls - a student enrolls in a subject

STUDENT

enrolls

SUBJECT

Relationships may also have attributes


16

Degree of a Relationship

The number of entity types attached to a relationship Three (3) most common types

Unary relationship Binary relationship Ternary relationship

17

Unary Relationship

A recursive relationship within a single entity Exists within an entity to link related instances of that entity together

PERSON

is married to

18

Binary Relationship

An association between two entity types Most common relationship

STUDENT

enrolls

SUBJECT

19

Ternary Relationship

An association among three related entity types


PART

VENDOR

ships

WAREHOUSE

20

Optional and Mandatory Relationships

Optional Relationship

An instance of one entity may not be associated with an instance of the related entity
Every instance in one entity type must be associated with at least one instance in the related entity

Mandatory Relationship

21

Types of Relationship

Three (3) possible types of relationship can exist between the occurrences of related entity types:

One-to-one relationship One-to-many relationship Many-to-many relationship

22

Cardinality

The number of instances that is associated between a pair of entity types The cardinality of the association from A to B is the maximum number of occurrences of B that can be associated with A A pair of associations can exist between any two entities:

Ex. from A to B and from B to A


23

Examples of Cardinality

24

Example Instance Association in a One-to-One Unary Relationship

25

Example Instance Association in a Many-to-Many Relationship

26

Optional and Mandatory Cardinality

Optional cardinality

If minimum cardinality is 0
If minimum cardinality is 1

Mandatory cardinality

Mandatory 1 cardinality
27

Optional and Mandatory Cardinality

Mandatory 1-Many cardinality Optional 0 or 1 cardinality Optional 0-Many cardinality


28

Maximum Cardinality Constraints

Here, maximum cardinality constraint is 4


29

Multiple Relationships

Entities can be related to one another in more than one way

30

Strong vs. Weak Entities, and Identifying Relationships

Strong entities

Exist independently of other types of entities Has its own unique identifier Represented with single-line rectangle Dependent on a strong entitycannot exist on its own; has no business meaning in the ERD without the entity (called identifying owner) it depends on Does not have a unique identifier, only partial identifier Represented with double-line rectangle Links strong entities to weak entities Represented with double line diamond
31

Weak entity

Identifying relationship

Example of Strong and Weak Entities

Strong entity

Identifying relationship

Weak entity

32

Associative Entities (Gerund)

Also known as composite entity A many-to-many relationship modeled as an entity type It is a relationship (but would want to maintain data about) It is an entity in disguise Has independent meaning to end-users and preferably identifiable by a single attribute

A gerund is represented by a diamond within a rectangle

SHIPMENT

33

Associative Entity Example


Emp # Name Date Completed Course ID Title

EMP

completes

COURSE

Emp #

Name

Date Completed

Course ID

Title

EMP

CERTIFICATE

COURSE

Certificate #
34

Associative Entity Example

35

Associative Entity Example

36

Supertypes and Subtypes

Subtype: A subgroup an entity type which has attributes that are distinct from those in other subgroups Supertype: An generic entity type that has a relationship with one or more subtypes Inheritance

Subtype entities inherit values of all attributes of the supertype An instance of a subtype is also an instance of the supertype
37

Basic Notation

38

Relationships and Subtypes

Relationships at the supertype level indicate that all subtypes will participate in the relationship The instances of a subtype may participate in a relationship unique to that subtype. In this situation, the relationship is shown at the subtype level
39

Example: Supertypes and Subtypes

40

Generalization & Specialization

Generalization

The process of defining a more general entity type from a set of more specialized entity type (bottom-up)
The process of defining one or more subtypes of the supertype and forming supertype/subtype relationships (topdown)
41

Specialization

Completeness Constraints

Whether an instance of a supertype must also be a member of at least one subtype

Total Specialization Rule: Yes (double line) Partial Specialization Rule: No (single line)

42

Total Specialization Rule

A patient must be either an outpatient or a resident patient

43

Partial Specialization Rule

A vehicle could be a car, a truck, or neither

44

Disjointness Constraints

Whether an instance of a supertype may simultaneously be a member of two (or more) subtypes Disjoint Rule: An instance of the supertype can be only ONE of the subtypes Overlap Rule: An instance of the supertype could be more than one of the subtypes
45

Disjointness Constraints

A patient can either be outpatient or resident, but not both

46

Overlap Constraints

A part may be both purchased and manufactured

47

Constraints in Supertype/Subtype Discriminators

Subtype Discriminator: An attribute of the supertype whose values determine the target subtype(s) Two types:

Disjoint a simple attribute with alternative values to indicate the possible subtypes Overlapping a composite attribute whose subparts pertain to different subtypes; each subpart contains a boolean value to indicate whether the instance belongs to associated subtype
48

Discriminator: Disjoint Rule

A simple attribute with different possible values indicating the subtype

49

Discriminator: Overlap Rule

A composite attribute with sub-attributes indicating yes or no to determine whether it is of each subtype

50

Supertype/Subtype Hierarchy

51

Entity Clusters

52

Inappropriate Diagrams

ERDs must not:

System user

System output

contain a user of the system contain an output of the database system (e.g. a report) be confused with a user view
53

Potrebbero piacerti anche