Understanding of Super Key, Candidate Key, Primary Key, Composite Key
Understanding of Super Key, Candidate Key, Primary Key, Composite Key
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.
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.
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
One to one
One to many
Many to one
Many to many
Types of Cardinalities
One to one
DEPT
Chair
Person
Many to many
EMP PROJ
PROJ EMP
Cardinality Example
STD BOOK
EMP PROJ
STD COURSE
STD HOBBY
Weak Entity Types