Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Lecture 07

Week 05
Understanding of Super Key, Candidate Key,
Primary Key, Composite Key
 I'll take example of an Employee table:
Employee (Employee ID, FullName, SSN, DeptID)

1. Candidate Key: are individual columns in a table


that qualifies for uniqueness of all the rows. Here in
Employee table EmployeeID & SSN are Candidate
keys.

2. Primary Key: is the columns you choose to


maintain uniqueness in a table. Here in Employee table
you can choose either EmployeeID or SSN columns,
EmployeeID is preferable choice, as SSN is a secure
value.
Understanding of Super Key, Candidate Key,
Primary Key, Composite Key
3. Alternate Key: Candidate column other the Primary column,
like if EmployeeID is PK then SSN would be the Alternate key.
4. Super Key: If you add any other column/attribute to a Primary
Key then it become a super key, like EmployeeID + FullName is
a Super Key.
5. Composite Key: If a table do have a single columns that
qualifies for a Candidate key, then you have to select 2 or more
columns to make a row unique. Like if there is no EmployeeID
or SSN columns, then you can make FullName + DateOfBirth as
Composite primary Key. But still there can be a narrow chance
of duplicate row.
Relationship Types, Relationship Sets,
Roles, and Structural Constraints

 Relationship
– When an attribute of one entity type refers to
another entity type
– Represent references as relationships not attributes
 Relationships are the connections and interactions
between the entities instances, e.g., Program and
Student ETs are linked
Relationship Types, Sets, and Instances
 Relationship type R among n entity types E1,
E2, ..., En
– Defines a set of associations among entities from
these entity types
– Relationship instances ri
– Each ri associates n individual entities (e1, e2, ..., en)
– Each entity ej in ri is a member of entity set Ej
– Relationship instances
 Relationship set: set of all relationships (r1, r2….rn)
Naming Relationships
 Up to you
 If there is no proper name of the association in the
system then participants’ names of abbreviations
are used
 STUDENT and CLASS have ENROLL
relationship
 However, it can also be named as STD_CLS
Naming Relationships
 Choose names that convey meanings attached
to different relationship
 Nouns give rise to entity type names, Verbs
indicate names of relationship types
 Choose binary relationship names to make ER
diagram readable from left to right and from
top to bottom
Symbol for Relationships

DEPT EMP

STD BOOK
Relationships Types
 Binary Relationship
– 2 Entities
 Ternary Relationship
– 3 Entities
 Unary Relationship
– 1 Entity
Binary Relationship Example

STD COURSE

STD BOOK

PROJ EMP
Attributes of the Relationships
 The relationships can have their descriptive
attributes
 Where to place

GRADE

STD COURSE
Ternary Relationships
 One that involves three entity types
 STUDENT-CLASS-FACULTY
 Instances in ordered triples
 Example {(S1013, MCS4, Adnan), (S1023, MCS3,
Fasih)}
STD COURSE
PROJ EMP

FACULTY
SKILL
Unary Relationship
 An ET linked with itself, also called recursive
relationship
 Example Roommate, where STUDENT is linked
with STUDENT
Unary Relationship Examples

STD ROOMMATE

EMP CHAIR-
PERSON

EMP SPOUSE
Constraints on Binary Relationship Types

 Number of instances of one entity type that can


possibly be related to instances of other entity type
 Cardinality ratio for a binary relationship
– Specifies maximum number of relationship instances
that entity can participate in
 Participation constraint
– Specifies whether existence of entity depends on its
being related to another entity
– Types: total (must participate)and partial (optional)
 Employee must have dept
 Employee may manage or not in any dept
Types of Cardinalities

One to one
One to many
Many to one
Many to many
Types of Cardinalities
One to one
DEPT
Chair
Person

One to many/ many to one


DEPT EMP

Many to many

EMP PROJ

PROJ EMP
Cardinality Example

STD BOOK

EMP PROJ

STD COURSE

STD HOBBY
Weak Entity Types

 Do not have key attributes of their own


– Identified by being related to specific entities
from another entity type
 Identifying relationship
– Relates a weak entity type to its owner
 Always has a total Cardinalities participation
constraint
Data Modeling Tools

 A number of popular tools that cover conceptual


modeling and mapping into relational schema
design:
– Examples: ErWin, S-Designer (Enterprise
Application Suit), ER-Studio etc.
– Advantages: Serve as a documentation of
application requirements, easy user interface,
mostly graphics editor support.
Practice :Questions
 Consider the ER diagram for part of a BANK database. Each bank can
have multiple branches, and each branch can have multiple accounts and
loans.
– a. List the strong (nonweak) entity types in the ER diagram.
– b. Is there a weak entity type? If so, give its name, partial key, and
identifying relationship.
– c. What constraints do the partial key and the identifying relationship
of the weak entity type specify in this diagram?
– d. List the names of all relationship types, and specify the (min, max)
constraint on each participation of an entity type in a relationship type.
Justify your choices.
– e. List concisely the user requirements that led to this ER schema
design.
– f. Suppose that every customer must have at least one account but is
restricted to at most two loans at a time, and that a bank branch cannot
have more than 1,000 loans. How does this show up on the (min,
max) constraints?
Consider the following environment of a university. There are academic
departments. Each department is identified by a 4 letter code, and has a
name, a chairperson, an office and a telephone extension. Each department
offers a set of courses. Each course is identified by the department code and
a 3 digit number, and has a title and number of units; each course may
require any number of prerequisite courses. Certain courses are currently
offered; an offering of a course is called a class. A class is identified by a 9
digit class number, is taught by a particular faculty, and meets 1-3 times a
week at the particular location. Each faculty is assigned to a single
department. Each faculty is identified by a social security number, and has a
name, a rank (e.g., assistant professor, associate professor, full professor),
and a telephone extension and a set of office hours. The chairperson of a
department is always assigned to that department. Each student is identified
by a SSN, and has a name, a major department, and an academic status (e.g.,
undergraduate, graduate, non-degree). Each student is currently enrolled in a
number of classes. For each course that the student had taken in the past, a
letter grade is available. All locations and office consist of a 3 letter building
code and a 3 digit room number. All telephone extensions are 4 digits.
ER- Diagram for Bank database

You might also like