0% found this document useful (0 votes)
15 views77 pages

ER Model Overview for Database Systems

The document outlines the tutorial schedule and consultation details for the CS2102 Database Systems course, including important dates and TA availability. It also covers fundamental concepts of SQL, integrity constraints, and the Entity-Relationship (ER) model for database design. The document emphasizes the importance of understanding data relationships and constraints in the context of database systems.

Uploaded by

tayruxin11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views77 pages

ER Model Overview for Database Systems

The document outlines the tutorial schedule and consultation details for the CS2102 Database Systems course, including important dates and TA availability. It also covers fundamental concepts of SQL, integrity constraints, and the Entity-Relationship (ER) model for database design. The document emphasizes the importance of understanding data relationships and constraints in the context of database systems.

Uploaded by

tayruxin11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CS2102

Database Systems
L03: ER Model
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 1 / 76
Tutorial

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 2 / 76


Tutorial
❱ Schedule Schedule
TAs

More Consultation Week 03

Tutorial Schedule

1 hour: All tutorials will be on Wednesday to Friday


COM4 SR33
not all tutorial questions will be discussed in class (challenge questions are not discussed)

Off-Days

Chinese New Year Eve Good Friday Hari Raya Puasa

Fri, 9 Feb 2024 Thu, 28 Mar 2024 Wed, 10 Apr 2024


Half-day up to 2pm Fri, 29 Mar 2024 (well-being) No tutorials for Week 10
Those affected may choose No tutorials for Week 10
to come to other session

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 3 / 76


Tutorial
Chua Shi Hong Darius Foo Do Ha Duong Meryl Seow
Schedule

❱ TAs
More Consultation

Ruby Nguyen Samay Sagar Su Yating Sumanth Yalamarty

Sun Bangjie Brigitte Santoso Pratham Jain Tan Yuan Zheng

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 4 / 76


Tutorial
Schedule
More Consultation
TAs

❱ More Consultation Weekly Schedule

TA Date Time Venue


Samay Sagar Wed 10:00 - 11:00 Zoom
Do Ha Duong Wed 15:00 - 16:00 Zoom
Darius Foo Thu 16:00 - 17:00 Zoom

Note

More will be added and the information will be made


available on Canvas page.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 5 / 76


Recap

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 6 / 76


Recap
❱ SQL SQL
Basic

Table Basic
Rows

Integrity Constraints What Is It?

Principles The standard language for RDBMS


Different language groups: DDL, DML, DQL, DCL, TCL
DDL: CREATE TABLE, ALTER TABLE, DROP TABLE
DML: INSERT, UPDATE, DELETE

Key Challenge

Specification of integrity constraints


NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK
Specification actions in case of foreign key constraint violations (ON UPDATE/ON DELETE)
Relaxed checks of violations with deferrable constraints

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 7 / 76


Recap
❱ SQL SQL
Basic

Table Table Operations


Rows

Integrity Constraints CREATE TABLE ALTER TABLE

Principles
CREATE TABLE <table_name> ( ALTER TABLE <table_name>
<attr_1> <type_1> [<column_constraint_1>], [ALTER / ADD / DROP]
[COLUMN / CONSTRAINT] <name>
<attr_2> <type_2> [<column_constraint_2>],
<changes>;

<attr_n> <type_n> [<column_constraint_n>],
[<table_constraint_1>], -- single line comment
[<table_constraint_2>], /* multi-line comment */
DROP TABLE

[<table_constraint_m>] -- no comma at the end DROP TABLE [IF EXISTS] <table_name>;
);

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 8 / 76


Recap
❱ SQL SQL
Basic

Table Rows Operations


Rows

Integrity Constraints INSERT

Principles
INSERT INTO <table_name> [(<attr>, ...)] VALUES (<values>, ...) [, (<values>, ...)];

UPDATE

UPDATE <table_name> SET <attr> = <value> [, <attr> = <value>] [ WHERE <condition> ];

DELETE

DELETE FROM <table_name> [ WHERE <condition> ];

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 9 / 76


Recap
SQL
Integrity Constraints
❱ Integrity Constraints
Principles Kinds

Type Column Table Condition


Not-NULL NOT NULL CHECK (A IS NOT NULL) NOT NULL

Unique UNIQUE UNIQUE (A1,A2,...) ∃Ai : [Link] <> [Link]

Primary Key PRIMARY KEY PRIMARY KEY (A1,A2,...) UNIQUE & NOT NULL
The tuple exists in R1
FOREIGN KEY (A1,A2,...,An) or the tuple (a1,a2,...,an)
Foreign Key REFERENCES R1(B)
REFERENCES R1(B1,B2,...,Bn) contains NULL value such that
ai ∈ Dom(Ai)

General CHECK (c) CHECK (c) Condition c does not evaluate to False

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 10 / 76


Recap
SQL
Principles
Integrity Constraints

❱ Principles Two Main Principles

Principle of Acceptance

In principle of acceptance, we perform the operation if the condition evaluates to True.


Used in the WHERE clause of SQL

Principle of Rejection

In principle of rejection, we reject the insertion if the condition evaluates to False.


Used in integrity constraints

Three-Valued Logic

SQL uses three-valued logic


Mental Model: NULL values are ALL possible values at the same time

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 11 / 76


Roadmap

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 12 / 76


Roadmap
❱ Overview Overview
Sections

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 13 / 76


Roadmap
Overview
Sections
❱ Sections
Preliminary

Database Design Process

Entity Relationship Relational Mapping

ER Diagram Schema Generation


Entity Sets & Attributes Constraint Satisfaction
Relationship Sets

Relationship Constraints Extended Notations

Cardinality Constraints ISA Hierarchies


Participation Constraints Aggregations

Why Design?

House built, Boss. And the bricks laid evenly? It couldn't be more even, Boss

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 14 / 76


Preliminary

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 15 / 76


Preliminary
❱ Design Steps Design Steps
Open Questions

Design Process Open Questions

We Sneakily Skipped a Step

Where does a database schema come from?


What tables with which attributes do we need?
What data integrity constraints are required?
What table names, attribute names, data types, etc do we need?

Basic Considerations

Separate what should be data and what should be operations


Data: Values that when stored, indicates a truth
We assume that the data inserted is correct
You may be required to move/update/delete/insert data
e.g., if there is an entry in Flights, there should be an actual flight

Operations: An action to obtain the data


e.g., the database does not care how an airplane actually playing

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 16 / 76


Preliminary
❱ Design Steps Design Steps
Open Questions

Design Process Design Process


Identification and collection of user needs
Requirement Analysis
e.g., data / application / performance requirements

Capturing requirements using conceptual model


Conceptual Database Design
RDBMS: Entity Relationship Model (ER Model)

Mapping conceptual model to logical schema


Logical Database Design
RDBMS: ER Model → Relational Schema

Refine the relational schema


Schema Refinement
Check for and remove reduncancies and anomalies

Implementing database based on final schema


Physical Database Design
with consideration of performance requirements

Identification of users and user groups and their


Security Design
permissions to access which parts of the data

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 17 / 76


Entity Relationship

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 18 / 76


Entity Relationship
❱ Preliminary Preliminary
Analysis

Concepts Analysis
Elements
Online Airline Reservation Systems
Concepts

Users need to be able to make bookings from an origin to a


destination airport which may comprise multiple connecting
flights. We record the booking date. Each flight has a flight
number, the origin and destination airport, the distance in
kilometers, the departure and arrival time, and the days of the
week the flight is in operation.

A flight instance is the actual scheduled flight on a given day


together with the assigned aircraft type. For example, flight SQ231
flies daily from Singapore to Sydney, typically with a Boeing 777-
300ER (code: B77W).

For a valid booking, we need the user's name, age, address,


phone number(s), and the passport number. Users are only able
to pay via credit card. When making a booking, the user can select
the class, the seat number, as well as meal preferences (if
available).

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 19 / 76


Entity Relationship
❱ Preliminary Preliminary
Analysis

Concepts Concepts
Elements
What Is It? Advantage
Concepts

The most common model for conceptual database design The diagram can be understood with
Developed by Peter Chen in 1976 less practice than that of reading code.
Visualized using ER Diagrams

Core Concepts

All data is described in terms of


Entities (nouns, rectangles)
Relationships (verbs, diamonds)
Attributes describe information about entities and
relationships
Elements are connected via lines
Certain data constraints can be described using additional
annotations

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 20 / 76


Entity Relationship
Preliminary
Elements
❱ Elements
Entities Entities
Attributes

Relationships Entity Users need to be able to make bookings


from an origin to a destination airport
Concepts An entity is a representation of real-world objects that are
which may comprise multiple connecting
distinguishable from other objects.
flights. Each flight has a flight number,
(e.g., a user, an airport, a flight, or a booking✱)
[...]

Entity Set

An entity set is a collection of entities of the same type.


Represented by a rectangle in ER diagrams
Names are typically nouns
Should not be proper nouns (e.g., Albert Einstein)
As a good practice, make the name plurals


While "booking" is a noun (e.g., "user makes a booking"), its root word may also be used as a verb (e.g., "user books a flight").
Careful judgment needs to be made whether it is an entity or a relationship.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 21 / 76
Entity Relationship
Preliminary
Elements
❱ Elements
Entities Attributes
Attributes

Relationships Attribute For a valid booking, we need the user's


name, age, address, phone number(s),
Concepts Attributes are specific information describing an entity or a
and the passport number. Users are only
relationship
able to pay via credit card. [...]
Represented by an oval in ER diagrams

Kinds

1. Key Attributes (underlined)


Uniquely identifies each entity (e.g., uid)
2. Composite Attributes (composed of other ovals, 1-level only)
Composed of multiple other attributes (e.g., address)
3. Multi-Valued Attributes (double-lined)
One or more values for a given entity (e.g., phone)
4. Derived Attributes (dashed line)
Derived from other attributes (e.g., age)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 22 / 76


Addendum
Entity Relationship As a best practice, try to make your ER diagram "readable". This can be achieved by arranging
and naming such that you can easily read the diagram
Preliminary left-to-right
Elements top-to-bottom
❱ Elements
Entities Relationships
Attributes

Relationships
Relationship Users need to be able to make bookings
[...] We record the booking date. [...]
Concepts A relationship is an association among one or more entities.
(e.g., users make bookings)

Relationship Set

An relationship set is a collection of relationships of the same


type.
Represented by a diamond in ER diagrams
Names are typically verbs
May have their own attributes (further describe the relationhsip)

Additional Concepts

Roles Cardinalities Dependencies


Degrees Participations

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 23 / 76


Entity Relationship
Preliminary
Concepts
Elements

❱ Concepts Roles
Roles

Degrees
Relationship Role [...] from an origin to a destination
airport which may comprime multiple
A relationship role is a descriptor of an entity set's participation
connecting flights [...]
in a relationship
Most of the time, it is implicitly given by the name of the entity
sets
Explicit role label only in case of ambiguities


We may also add roles on the line between Flights and travels to further describe the relationship but this is optional.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 24 / 76
Entity Relationship
Preliminary
Concepts
Elements

❱ Concepts Degrees
Roles
"In typical modeling, binary relationships are
Degree of Relationship Sets
Degrees the most common and relationships with n>3 are
The degree of a relationship sets is the number of entity sets very rare"
-- Peter Chen (2009)
involved in the relationship set
If there are n entities, we call it n-ary relationship
In principle, there is no limitation on the number of entity sets
involved

Binary Relationship Set (n = 2) Ternary Relationship Set (n = 3) General n-ary

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 25 / 76


Relationship Constraints

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 26 / 76


Relationship Constraints
❱ Preliminary Preliminary
Basic

Kinds Basic
Cardinalities
Relationships
Participations

Dependency Relationships relates one or more entities. We only record True relationships. In other words, if the information is
Summary
available in the database, the relationship is true.

Example ER Diagram Possible Information


Users Bookings Makes

uid ... bid ... uid bid ...


u01 ... b11 ... u01 b11 ...
u02 ... b12 ... u02 b12 ...
u03 ... b13 ... u01 b13 ...
u04 ... u03 NULL ...

Not all users are in "Makes" (there is a user not related to booking).
Users not making bookings are not in Makes (e.g., with NULL value for "bid").
The last row in "Makes" is not allowed.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 27 / 76


Addendum
Relationship Constraints Our ER diagram notation uses the look here notation. In other words, a particular connection
(e.g., line, arrow, double-line, etc) captures the constraint with respect to the two elements
❱ Preliminary Preliminary
being connected.
Basic

Kinds Kinds
Cardinalities
Cardinality Constraints
Participations

Dependency Describes an upper bound to the number of times an entity can participate in a relationship (either 1 or ∞)
Summary Upper limits of 1 are called key constraints

Participation Constraints

Describes an lower bound to the number of times an entity can participate in a relationship (either 0 or 1)
Lower limits of 0 are called partial participation constraints
Lower limits of 1 are called total participation constraints

Dependency Constraints

Describes a weak entity set that does NOT have its own key (its keys are called partial keys)
Its existence is also dependent on owning entity set
Entities that are not weak are called strong entity sets

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 28 / 76


Relationship Constraints
Preliminary
Cardinalities
❱ Cardinalities
Many-to-Many Basic Cardinality Constraints
Many-to-One

One-to-One Binary Relationship Cardinality

Participations 1. Many-to-Many e.g., a flight can be performed by different aircrafts; an aircraft can perform different flights
Dependency 2. Many-to-One e.g., a user can make many bookings, but each booking is done by one user
Summary
3. One-to-One e.g., a user is associated with one set of credit card details, and vice versa

ER Diagram

Default upper limit is ∞ and is specified by a line


Upper limit of 1 is specified by an arrow (i.e., →)
The annotations can work with n-ary relationship

Upper Limit = ∞ Upper Limit = 1

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 29 / 76


Relationship Constraints
Preliminary
Cardinalities
❱ Cardinalities
Many-to-Many Many-to-Many
Many-to-One

One-to-One Example

Participations Each booking can include 0 or more flights✱ and each flight can be part of 0 or more bookings.
Dependency

Summary
ER Diagram Visualization

Explanation ☞
There can be a booking with
different flights (e.g., 83465)
There can be a flight with
different bookings (e.g., EY454)
There can be a booking without
flight (e.g., 89557)
There can be a flight without
booking (e.g., SQ7952)


A booking with 0 flights might not be meaningful and we will improve on that.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 30 / 76
Relationship Constraints
Preliminary
Cardinalities
❱ Cardinalities
Many-to-Many Many-to-One
Many-to-One

One-to-One Example

Participations Each user can include 0 or more bookings and each booking can be made by at most 1 user✱.
Dependency

Summary
ER Diagram Visualization

Explanation ☞
There are no booking with
different users
There can be a user with
different bookings (e.g., 103)
There can be a booking without
user (e.g., 18545)
There can be a user without
booking (e.g., 102)


Still not perfect yet because what is a booking that is made by no user? We will also improve on that.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 31 / 76
Relationship Constraints
Preliminary
Cardinalities
❱ Cardinalities
Many-to-Many One-to-One
Many-to-One

One-to-One
Example

Participations Each user can provide at most 1 credit card and each credit card is associated to at most 1 user✱.
Dependency

Summary
ER Diagram Visualization

Explanation

There are no user with


different credit card
There are no credit card with
different user
There can be a user without
credit card (e.g., 102)
There can be a credit card
without user (e.g., 5678-...)


May be too strict, because a family may share a single credit card.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 32 / 76
Relationship Constraints
Preliminary
Participations
Cardinalities

❱ Participations Basic Participation Constraints


Total
Limitation of Cardinality Constraints
Key + Total

Dependency Cardinality constraints only specify the upper bound


Summary
A booking can be made by at most 1 user
Cardinality does not specify the lower bound
A booking can include 0 flights
Can be specified by participation constraints

ER Diagram

Default lower limit is 0 and is specified by a line


Lower limit of 1 is specified by double line (i.e., =)
The annotations can work with n-ary relationship

Lower Limit = 0 Lower Limit = 1

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 33 / 76


Relationship Constraints
Preliminary
Participations
Cardinalities

❱ Participations Total Participation


Total
Example
Key + Total

Dependency Each user booking includes at least 1 flights and each flight can be art of 0 or more bookings.
Summary

ER Diagram Visualization

Explanation ☜
There can be a booking with
different flights (e.g., 83465)
There can be a flight with
different bookings (e.g., EY454)
There are no booking without a
flight
There can be a flight without
booking (e.g., SQ7952)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 34 / 76


Relationship Constraints
Preliminary
Participations
Cardinalities

❱ Participations Key + Total Participation


Total
Example
Key + Total

Dependency Each user can make 0 or more bookings and each booking can be made by exactly 1 user.
Summary

ER Diagram Visualization

Explanation ☜
There are no booking with
different users
There can be a user with
different bookings (e.g., 103)
There are no booking without
user
There can be a user without
booking (e.g., 102)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 35 / 76


Addendum
Relationship Constraints The notation we use is
Double line around weak entity set and identifying relationship set
Preliminary Key + Total Participation constraint of weak entity set with respect to identifying
Dependency relationship set
Cardinalities

Participations Weak Entity


❱ Dependency
Definition
Weak Entity

Example A weak entity set is an entity set that does NOT have its own key
Summary
Its key is called partial key
Its key cannot uniquely identify an entity
Its key can uniquely identify an entity with the help of the key from owning entity set

Properties Example

Existence of weak entity is dependent on the existence of its owner A book chapter is dependent on a
Requirements
× entity book and a book chapter cannot
Weak entity set must be connected to an owning entity set via uniquely identify a chapter
For an entity set to be a identifying relationship set without book name
weak entity set, it must
satisfy all of these:
1. Its keys are partial keys
2. Existence of its entity is
dependent on the ER Diagram
existence of owning
entity (i.e., existence
dependency)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 36 / 76


Relationship Constraints
Preliminary
Dependency
Cardinalities

Participations Example
❱ Dependency ISBN: 0-07-232206-3 ISBN: 0-07-246563-8
Weak Entity

Example

Summary

Note

"Chapter 3: The Relational Model" cannot uniquely identify the rest of the attributes (e.g., subchapters)?

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 37 / 76


Relationship Constraints
Preliminary
Summary
Cardinalities

Participations Relationship Constraints


Dependency Name Constraint Diagram
❱ Summary
Each instance of E may participate in 0 or more
Unconstrained
instance of R

Each instance of E participates in at most 1 instance


Key Constraint
of R

Each instance of E participates in at least 1 instance


Total Participation
of R

Each instance of E participates in exactly 1 instance


Key + Total Participation
of R

Weak Entity + Identifying E is a weak entity set with identifying owner E' and
Relationship indentifying relationship set R

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 38 / 76


Relational Mapping

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 39 / 76


Relational Mapping
❱ Preliminary Preliminary
Constraints

Entity Set Constraints


Relationship Set
Main Constraints
Guidelines

There are three main constraints that need to be satisfied on a general ER diagram.

1. Can the key attributes uniquely identify the rest of the attributes?
This applies to entity set
Additionally, key attributes should not uniquely identify additional attributes not part of the entity set unless
bound constraints requires it

2. Are the lower bound constraints satisfied?


Complex ER Diagram
Can the lower bound be 0?
Can the lower bound be 1? Our discussion involves simple ER diagram (i.e., involve at most 1 relationship
set). For a more complex ER diagram, you should translate the ER diagram
from the element with the fewest number of restrictions (e.g., fewest foreign
3. Are the upper bound constraints satisfied? key constraints).

Can the upper bound be ∞?


Can the upper bound be 1?

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 40 / 76


Relational Mapping
Preliminary
Entity Set
❱ Entity Set
Basic Mapping Basic Mapping
Key Attributes

Composite Attributes Entity Set to Schema Data Type?

Multi-Valued Attributes
ER Diagram Schema ER diagram does not capture the data
Relationship Set type. We assume that the data type is as
Name of entity set Name of table
Guidelines logical as possible.
Attribute of entity set Attribute/column of table name ≠ INT
Key attribute of entity set Primary key of table price ≠ INT
Derived attribute of entity set should not appear✱ (should be NUMERIC and not FLOAT or
FLOAT8 or DOUBLE too)

Other Constraints?

ER diagram has limited expressibility


Many constraints cannot be encoded except via complicated tricks (e.g., not NULL, UNIQUE, data type)
You do not have to mention that an attribute is NOT NULL is not enforced
General constraints cannot be encoded


Derived attributes are derived, it means that there is a computation that can be used to generate them from the row or from
other table. Typically used for attributes that frequently change (e.g., age).
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 41 / 76
Relational Mapping
Preliminary
Entity Set
❱ Entity Set
Basic Mapping Key Attributes
Key Attributes
ER Diagram
Composite Attributes Strategy

Multi-Valued Attributes
Key attributes can be enforced via PRIMARY KEY
Relationship Set constraint
Guidelines ER diagram can only encode one set of key for
each entity set

Schema Table

CREATE TABLE Users ( uid name dob passport


uid INT PRIMARY KEY,
name VARCHAR(100),
dob DATE,
passport VARCHAR(20) Note

);
The attribute age is not present in the translation (i.e.,
not in the table) as it can be computed from the
attribute dob instead.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 42 / 76


Relational Mapping
Preliminary
Entity Set
❱ Entity Set
Basic Mapping Composite Attributes
Key Attributes
ER Diagram
Composite Attributes
Strategy

Multi-Valued Attributes
Composite attributes are converted into a series
Relationship Set of single-valued attributes corresponding to the
Guidelines decomposed attributes
Tables should only hold atomic values

Schema Table

CREATE TABLE Users ( uid ... street block zip


uid INT PRIMARY KEY,
:
street VARCHAR(50),
block VARCHAR(6), Note

zip INT
The attribute address is not present in the
); translation as it can be reproduced from the
attribute street, block, and zip instead.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 43 / 76


Relational Mapping
Preliminary
Entity Set
❱ Entity Set
Basic Mapping Multi-Valued Attributes
Key Attributes
ER Diagram
Composite Attributes Strategy #1

Multi-Valued Attributes
Convert multi-valued attributes into a sequence of
Relationship Set single-valued attributes
Guidelines Limitation: can only have a fixed number of
attributes

Schema Table

CREATE TABLE Users ( uid ... phone1 phone2 phone3


uid INT PRIMARY KEY,
:
phone1 INT,
phone2 INT, Problems

phone3 INT
Searching for a user with certain phone numbers
); is more complicated
Ensuring that phone1 is filled before phone2 and
phone3

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 44 / 76


Relational Mapping
Preliminary
Entity Set
❱ Entity Set
Basic Mapping Multi-Valued Attributes
Key Attributes
ER Diagram
Composite Attributes Strategy #2

Multi-Valued Attributes
Create additional table with foreign key constraint
Relationship Set Limitation: retrieval requires joining two tables
Guidelines which can be more expensive

Schema Table

CREATE TABLE Users ( ... ); uid ...


CREATE TABLE Phones (
uid INT,
phone INT,
uid phone
FOREIGN KEY (uid) REFERENCES Users(uid)
);


Unless the multiplicity of the attributes is known in advanced, you should use Strategy #2 instead.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 45 / 76
Relational Mapping
Preliminary
Relationship Set
Entity Set

❱ Relationship Set Basic Mapping


Basic Mapping
General n-ary Relationship Set R Simplification
Many-to-Many

Many-to-One n entity sets E1, E2, ..., En We assume each entity sets involved only have
One-to-One m attributes A1, A2, ..., Am one key denoted by keyE_i for entity set Ei
Key + Total Extension can be made for entity sets with
Weak Entity Set We assume unconstrained relationship multiple key attributes using table constraint
Guidelines

ER Diagram General Schema

CREATE TABLE R (
keyE_1 TYPE REFERENCES E_1,
keyE_2 TYPE REFERENCES E_2,
: :
keyE_n TYPE REFERENCES E_n,
A_1 TYPE,
A_2 TYPE,
: :
A_m TYPE,
PRIMARY KEY (keyE_1, keyE_2, ..., keyE_n)
);

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 46 / 76


Quiz #1
Relational Mapping
Where does the attribute fnum comes from?
Preliminary
Relationship Set
Entity Set

❱ Relationship Set Many-to-Many


Basic Mapping ER Diagram
Many-to-Many

Many-to-One

One-to-One

Key + Total

Weak Entity Set

Guidelines

Strategy

CREATE TABLE FlightInstances ( CREATE TABLE Includes (


fnum INT REFERENCES Flights, fdate DATE,
fdate DATE, fnum INT,
aircraft VARCHAR(10), bid INT REFERENCES Bookings,
PRIMARY KEY (fnum, fdate) seat VARCHAR(10),
); FOREIGN KEY (fnum, fdate) REFERENCES FlightInstances,
CREATE TABLE Bookings ( PRIMARY KEY (fnum, fdate, bid)
bid INT PRIMARY KEY );
);

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 47 / 76


Quiz #2
Relational Mapping
How do we find users who did not make any bookings?
Preliminary
Relationship Set
Entity Set

❱ Relationship Set Many-to-One


×
Basic Mapping
Constraints Enforced ER Diagram
Many-to-Many
uid uniquely identify
dob and uname
Many-to-One

Users entity
One-to-One
bid uniquely identify
Key + Total
bdate
Weak Entity entity
Bookings Set
We cannot have both
Guidelines
(bid, uid1) and
(bid, uid2) in Makes Strategy #1: Separate Tables
Upper bound = 1
We may have both CREATE TABLE Users ( CREATE TABLE Makes (
(bid1, uid) and uid INT PRIMARY KEY, uid INT NOT NULL, -- not NULL to avoid redundant info
(bid2, uid) in Makes
Upper bound = ∞ uname VARCHAR(100), bid INT,
If a uid is in Users, it dob DATE ‎
need not necessarily be ); FOREIGN KEY (uid) REFERENCES Users (uid),
in Makes
Lower bound = 0 CREATE TABLE Bookings ( FOREIGN KEY (bid) REFERENCES Bookings (bid),
If a bid is in Bookings, bid INT PRIMARY KEY, PRIMARY KEY (bid)
it need not necessarily
bdate DATE );
be in Makes
Lower bound = 0 );

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 48 / 76


Quiz #3
Relational Mapping
Which approach is preferrable?
Preliminary
Relationship Set
Entity Set
×

Constraints Enforced
Relationship Set Many-to-One
uniquely
uid Mapping
Basic identify ER Diagram
dob and uname
Many-to-Many
Users entity
bid uniquely identify
Many-to-One

bdate
One-to-One
Bookings entity
Key + Total
We cannot have both
(bid,
Weak Entity uid1)
Set and
(bid, uid2) in
Guidelines
MakesBookings
Upper bound = 1 Strategy #2: Combined Tables
We may have both
(bid1, uid) and CREATE TABLE Users ( CREATE TABLE MakesBookings (
(bid2, uid) in uid INT PRIMARY KEY, uid INT, -- can be NULL (i.e., no corresponding uid)
MakesBookings
Upper bound = ∞ uname VARCHAR(100), bid INT,
If a uid is in Users, it dob DATE bdate DATE, -- Bookings attribute from merging
need not necessarily be ); FOREIGN KEY (uid) REFERENCES Users (uid),
in MakesBookings
Lower bound = 0 -- In this approach, we remove -- no more REFERENCES Bookings (bid)
If a bid is in -- "Bookings" and combine with PRIMARY KEY (bid)
MakesBookings, it need
-- "makes" into a single table );
not necessarily has the
corresponding uid -- called MakesBookings
Lower bound = 0

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 49 / 76


Quiz #4
Relational Mapping
Is there another implementation with more tables?
Preliminary
Relationship Set
Entity Set
×

Constraints Enforced
Relationship Set One-to-One
uniquely
uid Mapping
Basic identify ER Diagram
dob and uname
Many-to-Many
Users entity
Many-to-One
ccnum uniquely identify
exp
One-to-One
CreditCards entity
Key + Total
We cannot have both
(uid,
Weak Entityccnum1)
Set and
(uid, ccnum2) in
Guidelines
CreditCards and
Users Strategy #1: Separate Tables
Upper bound = 1
We cannot have both CREATE TABLE Users ( CREATE TABLE CreditCards (
(ccnum, uid1) and uid INT PRIMARY KEY, ccnum INT PRIMARY KEY,
(ccnum, uid2) in
CreditCards and uname VARCHAR(100), exp DATE,
Users dob DATE, ‎
Upper bound = 1
ccnum INT UNIQUE -- can be NULL uid INT UNIQUE -- can be NULL
We may have uid
without ccnum in Users REFERENCES CreditCards (ccnum) REFERENCES Users (uid)
Lower bound = 0 ); );
We may have ccnum
-- If ccnum is NULL it is a user -- If uid is NULL, it is a credit card without user
without uid in
CreditCards -- without credit card
Lower bound = 0


This is an example of "Circular Reference".
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 50 / 76
Relational Mapping
Preliminary
Relationship Set
Entity Set Enforced ×
Constraints

❱ Relationship Set
uid uniquely identify
One-to-One
Basic and uname
dob Mapping ER Diagram
Users entity
Many-to-Many
ccnum uniquely identify
Many-to-One
exp
CreditCards entity
One-to-One
We cannot have both
Key + Total
(uid, ccnum1) and
(uid,
Weak Entityccnum2)
Set in
Users
Guidelines
Upper bound = 1
We cannot have both Strategy #2: Combined Tables
(ccnum, uid1) and
(ccnum, uid2) in -- Alternative #1 -- Alternative #2
CreditCards CREATE TABLE Users ( CREATE TABLE Users (
Upper bound = 1
Cannot have uid uid INT PRIMARY KEY, uid INT UNIQUE,
without ccnum in uname VARCHAR(100), uname VARCHAR(100),
Alternative #2 dob DATE, dob DATE,
Lower bound = 0
Cannot have ccnum ccnum INT UNIQUE, ccnum INT PRIMARY KEY, -- ccnum is chosen as PK
without uid in exp DATE exp DATE
Alternative #1
); );
Lower bound = 0
Partial solution
-- uid is chosen as PK
Less preferrable


There is a "hidden" problem here, we can have user with no credit card in alternative #1 but there is an expiry date.
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 51 / 76
Quiz #5
Relational Mapping
Can we split Makes and Bookings into separate table?
Preliminary
Relationship Set
Entity Set Enforced ×
Constraints

❱ Relationship Set
uid uniquely identify
Key + Total
Basic and uname
dob Mapping ER Diagram
Users entity
Many-to-Many
bid uniquely identify
Many-to-One
bdate
Bookings entity
One-to-One
We cannot have both
Key + Total
(bid, uid1) and
(bid,
Weak uid2)
Entity Set in
MakesBookings
Guidelines
Upper bound = 1
We cannot have both Strategy: Combined Tables
(bid1, uid) and
(bid2, uid) in CREATE TABLE Users ( CREATE TABLE MakesBookings (
MakesBookings uid INT PRIMARY KEY, bid INT PRIMARY KEY,
Upper bound = ∞
Cannot have uid uname VARCHAR(100), bdate DATE,
without bid in Users dob DATE uid INT NOT NULL, -- ensures there must be a user!
Lower bound = 0 ); FOREIGN KEY (uid) REFERENCES Users (uid)
Cannot have bid
without uid in -- Users cannot be combined as it );
MakesBookings -- needs to identify dob and uname -- if we combine Users into MakesBooking, we may have
Lower bound = 1 -- (i.e., it is the PK of Users) -- (bid, uid, uname1) and (bid, uid, uname2)
Due to NOT NULL
-- see example on MakesBookings

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 52 / 76


Relational Mapping
Preliminary
Relationship Set
Entity Set

❱ Relationship Set Weak Entity Set


Basic Mapping ER Diagram
Many-to-Many ×
Constraints Enforced
Many-to-One
fnum uniquely
One-to-One identify
orig and dest
Key + Total entity
Flights
fdate
Weak Entitycannot
Set identify
aircraft
Guidelines
FlightInstances
Weak entity Strategy: Combined Tables
FlightInstances
cannot exist without CREATE TABLE Flights ( CREATE TABLE FlightInstances (
Flights
fnum cannot be NULL fnum INT PRIMARY KEY, fnum INT REFERENCES Flights (fnum)
(it is PK) orig VARCHAR(10), ON DELETE CASCADE -- existence is dependent
fnum references
Flights
dest VARCHAR(10) ON UPDATE CASCADE, -- on Flights fnum
If Flights is deleted, ); fdate DATE,
the corresponding -- Note that we do not have aircraft VARCHAR(10),
FlightInstances is
deleted -- "has" relationship set in the PRIMARY KEY (fnum, fdate) -- fdate is partial key
ON DELETE CASCADE -- schema for the same reason as );
Further enforces
dependency on the
-- key + total translation
existence

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 53 / 76


Relational Mapping
Preliminary
Guidelines
Entity Set

Relationship Set General Guidelines


❱ Guidelines
Separation of Concern

Determine which are data and which are operations


Captures only data and the constraints around the data
Note that the data may be split across multiple tables

Guidelines for ER Design Guidelines for Relational Mapping

An ER diagram should capture as many The relational schema should capture as many
constraints as possible (from the requirements) constraints as possible (from the requirements)
An ER diagram must NOT impose any constraints Using column and/or table constraints (e.g., NOT
that are not required (by the requirements) NULL, UNIQUE, CHECK (...), etc)
Attributes should have the same name if and only The relational schema must NOT impose any
if they are semantically equivalent constraints that are not required (by the
Often called the Universal Schema assumption requirements)
(makes query easier) The relational schema should use logical data
types (e.g., names/price should not be INT)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 54 / 76


Extended Notations

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 55 / 76


Extended Notations
❱ ISA Hierarchies ISA Hierarchies
Basic

Interpretation Basic
Constraints

Notation Definition ER Diagram


Example
The ISA hierarchies is a special type of relationship Represented as triangle connecting entity
Relational Mapping
representing the "is a" relationship. This model sets
Aggregation generalization and specialization of entity sets similar to Good Practice: Place the generalized entity
superclass and subclass relationship. set (superclass) on top

General Representation Example

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 56 / 76


Addendum
Extended Notations Specialized entity set should not "shadow" attributes from generalized entity set (i.e., attributes
with the same name as attributes from generalized entity set)
❱ ISA Hierarchies ISA Hierarchies
Basic

Interpretation Interpretation
Constraints

Notation ISA Interpretation ER Diagram


Example
Every entity in a specialized (i.e., subclass)
Relational Mapping
entity set is an entity in its generalized (i.e.,
Aggregation superclass) entity set
All attributes in generalized entity set is
inherited by specialized entity set
Specialized entity set must be uniquely
identified by the same key attributes of
generalized entity set
(i.e., specialized entity set keys should NOT be
shown in ER diagram)
Each specialized (i.e., subclass) entity set may
have additional attributes and/or involved
in additional relationship
While not required, that is the reason why
we have ISA hierarchies
(e.g., additional relationship, restrict
relationship, etc)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 57 / 76


Extended Notations
❱ ISA Hierarchies ISA Hierarchies
Basic

Interpretation Constraints
Constraints

Notation Overlap Constraints Covering Constraints


Example

Relational Mapping Can a generalized entity belongs to multiple Must a generalized entity belong to at least 1
Aggregation
specialized entity set? specialized entity set?

True False True False

Generalized entity Generalized entity Generalized entity Generalized entity


CAN belongs to CANNOT belongs to MUST belong to at NEED NOT belong to
multiple specialized multiple specialized least 1 specialized any specialized
entity set entity set entity set entity set
(e.g., a person can be (e.g., a student is (e.g., there is no (e.g., not every person
both student and either graduate or student that is neither is a student or staff)
staff) undergraduate) graduate nor
undergraduate)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 58 / 76


Extended Notations
❱ ISA Hierarchies ISA Hierarchies
Basic

Interpretation Notation
Constraints

Notation Upper/Lower Bound


Example
Covering constraint TRUE sets the lower bound = 1
Relational Mapping
similar to total participation constraint
Aggregation
Overlap constraint FALSE sets the upper bound =
1 similar to key constraint

Note

To avoid ambiguity, we use the following convention:


Generalized entity set (i.e., superclass) should be
shown above the specialized entity set (i.e.,
subclass)
When overlap = TRUE and covering = FALSE, we
use dashed line to connect generalized entity set

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 59 / 76


Specification
Extended Notations A person may be both student and staff
A person may be neither a student nor staff
❱ ISA Hierarchies ISA Hierarchies
Each student is either an undergraduate or a graduate but not both✱
Each staff may be admin, research, teaching or any combination✱ of
Basic
these three roles
Interpretation Example A teaching staff cannot be a lecturer and TA
Constraints A teaching staff may be neither lecturer or TA
ER Diagram
Notation

Example

Relational Mapping

Aggregation


We typically omit "but not both" when using "either" and we typically omit "or any combination" when using "or"
(e.g., "each staff is an admin, research, or teaching").
CS2102: Database Systems -- Adi Yoga Sidi Prabawa 60 / 76
Quiz #6
Extended Notations
Can we also directly map the ISA hierarchies when overlap = FALSE or
covering = TRUE? If yes, how? If no, what kinds of problems will we face?
❱ ISA Hierarchies ISA Hierarchies
Basic

Interpretation Relational Mapping


Constraints

Notation General Strategy


Example
One relation per generalized and specialized entity sets (works well when overlap = TRUE and covering = FALSE).
Relational Mapping

Aggregation

ER Diagram Schema

CREATE TABLE Persons (


id VARCHAR(20) PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Students (
id VARCHAR(20) PRIMARY KEY
REFERENCES Persons (id) ON DELETE CASCADE
year INT, -- or DATE?
);
CREATE TABLE Grads (
id VARCHAR(20) PRIMARY KEY
REFERENCES Persons (id) ON DELETE CASCADE,
phone INT,
office VARCHAR(10)
);

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 61 / 76


Extended Notations
ISA Hierarchies
Aggregation
❱ Aggregation
Motivation Motivation
Idea

Relational Mapping Limitation of Current ER Diagram

Relationships only relates entity sets and not relationship sets


There are no relationships between entity sets and relationship sets

ER Diagram
Example

[...] For some projects worked on by students, GPU may be used


(i.e., some projects uses GPU and some not).

Limitations

Relationship between "works" and "uses" is not captured


"uses" should be a subset of "works", or
"uses" and "works" should be disjoint

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 62 / 76


Extended Notations
ISA Hierarchies
Aggregation
❱ Aggregation
Motivation Motivation
Idea

Relational Mapping Limitation of Current ER Diagram

Relationships only relates entity sets and not relationship sets


There are no relationships between entity sets and relationship sets

ER Diagram
Example

[...] For some projects worked on by students, GPU may be used


(i.e., some projects uses GPU and some not).

Limitations

GPU cannot be NULL because it is part of the primary key in


"uses"
All student must use GPU

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 63 / 76


Extended Notations
ISA Hierarchies
Aggregation
❱ Aggregation
Motivation Idea
Idea

Relational Mapping Relationship Set as Higher-Level Entity Sets

Aggregates is constructed as a relationship set (i.e., relates entity sets)


Aggregates may be used as entity set (i.e., can participate in relationships)

ER Diagram
Note

Aggregate is a relationship set (i.e., a diamond) and also an


entity set (i.e., a rectangle)
The rectangle should NOT touch the diamond
The key attributes are formed from the relationship set
Entity sets participating in the relationship set forming the
aggregates should touch the diamond
When using aggregate as an entity set, the line should be
connected to the rectangle

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 64 / 76


Extended Notations
ISA Hierarchies
Aggregation
❱ Aggregation
Motivation Relational Mapping
Idea

Relational Mapping
Existing Relations Foreign Key Constraints

Students( sid: INT ) ([Link]) ⇝ ([Link])


Projects( name: VARCHAR(50) ) ([Link]) ⇝ ([Link])
GPUs( gid: INT, mem: INT )
Works( sid: INT, name: VARCHAR(50) )
ER Diagram

Schema

CREATE TABLE Uses (


gid INT REFERENCES GPUs,
sid INT,
name VARCHAR(50),
hours NUMERIC, -- can have decimal point
PRIMARY KEY (gid, sid, pname),
FOREIGN KEY (sid, pname) REFERENCES Works (sid, pname)
); -- Foreign key to "Works"
-- treating "Works" like an entity set

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 65 / 76


Summary

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 66 / 76


Summary
❱ Summary Summary
Requirement

ER Model

Basic Relational Mapping

ER model is visualized by ER diagram Relational mapping is a translation of ER diagram


into database schema
Topic Concepts Not all constraints can be captured by ER diagram
(but may be captured by schema)
Entity Sets Not all constraints captured on ER diagram can be
Elements Relationship Set captured by schema
Attributes
Cardinality
Constraints Participation
Dependency
ISA Hierarchies
Extended
Aggregation

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 67 / 76


Additional Exercise
Summary
Can you improve the ER diagram?
Summary
Requirement
❱ Requirement
Analysis

Online Airline Reservation Systems

Users need to be able to make bookings from an origin to


a destination airport which may comprise multiple connecting
flights . We record the booking date. Each flight has a flight
number , the origin and destination airport, the distance in
kilometers, the departure and arrival time, and the days of the
week the flight is in operation.

A flight instance is the actual scheduled flight on a given day


together with the assigned aircraft type. For example, flight SQ231
flies daily from Singapore to Sydney, typically with a Boeing 777-
300ER (code: B77W).

For a valid booking, we need the user's name , age , add-


ress , phone number(s) , and the passport number . Users are
only able to pay via credit card . When making a booking, the
user can select the class, the seat number, as well as meal
preferences (if available).

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 68 / 76


postgres=# exit
Press any key to continue . . .

CS2102: Database Systems -- Adi Yoga Sidi Prabawa


Solutions
❱ Quiz #1 Quiz #1
Quiz #2

Quiz #3 Question
Quiz #4
Quiz #1
Quiz #5
Where does the attribute fnum comes from?
Quiz #6

Solution

The attribute comes from Flights because Flight_Instances is a weak entity set with Flights being the owning entity set.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 70 / 76


Solutions
Quiz #1
Quiz #2
❱ Quiz #2
Quiz #3 Question
Quiz #4
Quiz #2
Quiz #5
How do we find users who did not make any bookings?
Quiz #6

Solution

The table Users stores all user information (whether they have made bookings or not)
The table Bookings stores all booking information (whether it is made by a user or not)
The table Makes stores only bookings that have been booked by a user
In other words, it stores users who have made bookings
So we simply look for users who are in the table Users but not in the table Makes

The users in Users include the users in Makes. What we want is the users
that are in Users but not in Makes.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 71 / 76


Solutions
Quiz #1
Quiz #3
Quiz #2

❱ Quiz #3 Question
Quiz #4
Quiz #3
Quiz #5
Which approach is preferrable?
Quiz #6

Solution

This is more of a discussion but we will list some advantages of each approach.

Approach #1 Approach #2

We can find all pairs of bookings bid and users uid No need to look at Makes, and Bookings to find
that have made a booking. We simply look at the bdate of the bookings made by a certain user
Makes without the need to check that uid is NULL with a given uid as both are in MakesBookings.
as it cannot be NULL.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 72 / 76


Solutions
Quiz #1
Quiz #4
Quiz #2

Quiz #3 Question
❱ Quiz #4
Quiz #4
Quiz #5
Is there another implementation with more tables?
Quiz #6

Solution

Another implementation is to have 3 tables: Users, CreditCards, and Owns.

CREATE TABLE Users ( CREATE TABLE Owns (


uid INT PRIMARY KEY, uid INT REFERENCES Users (uid),
uname VARCHAR(100), ccnum INT NOT NULL REFERENCES CreditCards (ccnum)
dob DATE PRIMARY KEY (Users),
); UNIQUE (ccnum)
-- credit cards omitted ); -- can swap primary key and candidate key

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 73 / 76


Solutions
Quiz #1
Quiz #5
Quiz #2

Quiz #3 Question
Quiz #4
Quiz #5
❱ Quiz #5
Can we split Makes and Bookings into separate table?
Quiz #6

Solution

In this case, NO. If we split the table, then we cannot enforce the total participation constraint on Bookings with
respect to Makes. This is because we can insert into Bookings without many any insertion into Makes.

We will look at other ways to enforce this using triggers instead.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 74 / 76


Solutions
Quiz #1
Quiz #6
Quiz #2

Quiz #3 Question
Quiz #4
Quiz #6
Quiz #5
Can we also directly map the ISA hierarchies when overlap = FALSE or covering = TRUE? If yes, how? If no, what kinds of
❱ Quiz #6
problems will we face?

Solution

THere are "tricks" that we can use to enforce these but it involves adding redundant columns. We will not go into these
in details and we do not expect students to implement these tricks.

Without these tricks, the only other strategy we have is to not create a table for the generalized entity set. Instead, we
can make them into a VIEW (i.e., a computed table that adds no additional storage and is computed each time we want to query).

The problem with this approach is that the attributes of the generalized entity set have to be stored in the specialized
entity set. Firstly, it is a redundant storage. Secondly, we no longer can uniquely identify the attributes since they can
be different in different specialized entity sets.

The DBMS solution to this is to use triggers.

CS2102: Database Systems -- Adi Yoga Sidi Prabawa 75 / 76


(END)

CS2102: Database Systems -- Adi Yoga Sidi Prabawa

You might also like