28
Entity-Relationship Model Cont….. CST203-2 Database Management Systems Lecture 4

CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Embed Size (px)

DESCRIPTION

Keys A Key is a single attribute or combination of two or more attributes of an entity set that is used to identify one or more instances of the set

Citation preview

Page 1: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Entity-Relationship ModelCont…..

CST203-2 Database Management SystemsLecture 4

Page 2: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Student entity

NID FName LName RegNo ExamId Birthdate

Page 3: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Keys

A Key is a single attribute or combination of two or more attributes of an entity set that is used to identify one or more instances of the set

Page 4: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Student entity

NID FName LName RegNo ExamId Birthdate

Page 5: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Super KeyA super key of an entity set is a set of one or

more attributes whose values uniquely determine each entity.

A superkey is any set of attributes (K) such that no two tuples of a relation can have the same values for K, i.e: t1(K) != t2(K) for every possible pair of distinct tuples, t1,t2.

Page 6: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Student entity

NID FName LName RegNo ExamId Birthdate

Page 7: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Candidate KeyA candidate key is a superkey such that no

proper subset of K is also a superkey. Customer-id is candidate key of customeraccount-number is candidate key of account

Page 8: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Student entity

NID FName LName RegNo ExamId Birthdate

Page 9: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Primary keyAlthough several candidate keys may exist,

one of the candidate keys is selected to be the primary key.

Primary key does not allow duplicate values(repeating) and null values

Page 10: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Student entity

NID FName LName RegNo ExamId Birthdate

Page 11: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Unique keyIt wont allow duplicate values including

NULL...

Means that it will allow any thing only one time ....including null...

Page 12: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Strong entity typesRegular entity types which have a primary

key attributes

Page 13: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Weak Entity TypesAn entity type that does not have a primary key

The existence of a weak entity type depends on the existence of a identifying or owner entity type it must relate to the identifying entity set via a total, one-to-many

relationship set from the identifying to the weak entity setIdentifying relationship depicted using a double diamondTotal participation constraint

The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set.

Weak entity as an attribute

Page 14: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

We depict a weak entity set by double rectangles.

We underline the discriminator of a weak entity set with a dashed line.

payment-number – discriminator of the payment entity set

Primary key for payment – (loan-number, payment-number)

Page 15: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

In a university, a course is a strong entity and a course-offering can be modeled as a weak entity

The discriminator of course-offering would be semester (including year) and section-number (if there is more than one section)

If we model course-offering as a strong entity we would model course-number as an attribute. Then the relationship with course would be implicit in the course-number attribute

Page 16: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Design of ER diagramInitial design is created and then iteratively refined until the most suitable

design is reached

1. Concept may be first modeled as an attribute and then refined in to relationship(binary)

2. An attribute that exists in several entity types may be elevated or promoted to an independent entity type

e.g.: student, instructor, course has the common attribute department number

3. Inverse of 2nd one : if an entity type exists with a single attribute and is related to only one entity …….

4. Refine using specialization, generalization and relationships of higher degree

Page 17: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Specialization Top-down design process

we designate subgroupings within an entity set that are distinctive from other entities in the set.

Specific attributes

Specific relationships

Depicted by a triangle component labeled ISA (E.g. customer “is a” person).

Attribute inheritance – a lower-level entity set inherits all the attributes and relationship participation of the higher-level entity set to which it is linked

Page 18: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Specialization Example

Page 19: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

GeneralizationA bottom-up design process – combine a number of

entity sets that share the same features into a higher-level entity set.

Specialization and generalization are simple inversions of each other

they are represented in an E-R diagram in the same way.

The terms specialization and generalization are used interchangeably.

Page 20: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Specialization and GeneralizationCan have multiple specializations of an entity set based on

different features.

E.g. permanent-employee vs. temporary-employee, in addition to officer vs. secretary vs. teller

Each particular employee would be a member of one of permanent-employee or temporary-employee, and also a member of one of officer, secretary, or teller

The ISA relationship also referred to as superclass - subclass relationship

Page 21: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Design Constraints on a Specialization/Generalization Constraint on which entities can be members of a given lower-level entity set.

Condition-defined / predicate defined subclasses E.g. all customers over 65 years are members of senior-citizen entity set; senior-citizen ISA

person. User-defined specialization

Disjointness constraint Constraint on whether or not entities may belong to more than one lower-level entity set

within a single generalization. Disjoint

an entity can belong to only one lower-level entity set Noted in E-R diagram by writing disjoint next to the ISA triangle

Overlapping an entity can belong to more than one lower-level entity set

Completeness constraint -- specifies whether or not an entity in the higher-level entity set must belong to at least one of the lower-level entity sets within a generalization.

total specialization : an entity must belong to one of the lower-level entity sets Partial specialization : an entity need not belong to one of the lower-level entity sets

Page 22: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Insertion and deletion rules for specialization and generalizationDeleting from superclass

Inserting in a superclassPredicate defined specializationTotal specialization

Page 23: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

AggregationA class type really represents a collection of

individual components

Page 24: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

The system is an aggregation of components

It denotes an "is part of" relationship

Page 25: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

E-R Diagram for a Banking Enterprise

Page 26: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Summary of Symbols Used in E-R Notation

Page 27: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate
Page 28: CST203-2 Database Management Systems Lecture 4. Student entity NIDFNameLNameRegNoExamIdBirthdate

Alternative E-R Notations