Professional Documents
Culture Documents
DATA MODELING
Entity
• An entity can be a real-world object, either animate or
inanimate, that can be easily identifiable.
• For example, in a school database, students, teachers,
classes, and courses offered can be considered as entities.
• All these entities have some attributes or properties that give
them their identity.
Attributes
• Entities are represented by means of their properties,
called attributes. All attributes have values. For
example, a student entity may have name, class, and age
as attributes.
• There exists a domain or range of values that can be
assigned to attributes. For example, a student's name
cannot be a numeric value. It has to be alphabetic. A
student's age cannot be negative, etc.
Types of Attributes
Simple Vs Composite
●Simple or atomic attribute − Simple attributes are atomic values, which
cannot be divided further. For example, a student's phone number is an
atomic value of 10 digits.
• The stored attribute are such attributes which are already stored
in the database. For example , DOB.
l
superkey can also be just a single column.
Example of a superkey
Suppose we have a table that holds all the managers in a company, and that table is called
Managers. The table has columns called ManagerID, Name, Title, and DepartmentID.
Every manager has his/her own ManagerID, so that value is always unique in each and every
row. This means that if we combine the ManagerID column value for any given row with any
other column value, then we will have a unique set of values. So, for the combinations of
(ManagerID, Name), (ManagerID, TItle), (ManagerID, DepartmentID), (ManagerID, Name,
DepartmentID), etc
– there will be no two rows in the table that share the exact same combination of values,
because the ManagerID will always be unique and different for each row. This means that
pairing the Manager ID with any other column(s) will ensure that the combination will also be
unique across all rows in the table.
superkey – it’s any combination of column(s) for which that combination of values will be
unique across all rows in a table. So, all of those combinations of columns in the Manager
table that would be considered to be superkeys. Even the ManagerID column is considered to
be a superkey
Relationships and Relationship Types
• A relationship relates two or more distinct entities
with a specific meaning.
• For example, EMPLOYEE John Smith works on the
ProductX PROJECT, or EMPLOYEE Franklin Wong
manages the Research DEPARTMENT.
• Relationships of the same type are grouped or typed
into a relationship type.
• For example, the WORKS_ON relationship type in which
EMPLOYEEs and PROJECTs participate, or the
MANAGES relationship type in which EMPLOYEEs and
DEPARTMENTs participate.
Degree of Relationships
• The degree of a relationship type is the number of
participating entity types.
e1 r1 d1
e2
r2
d2
e3
r3
e4
r4 d3
e5
e6 r5
e7 r6
r7
Role Names
• Each entity type that participates in a relationship type plays
a particular role in the relationship.
• The role name signifies the role that a participating entity
from the entity type plays in each relationship instance, and
helps to explain what the relationship means.
• For example, in the WORKS_FOR relationship type,
EMPLOYEE plays the role of employee or worker and
DEPARTMENT plays the role of department or employer.
Constraints on Relationship Types
• Two main types of relationship constraints:
1. Cardinality ratio - The cardinality ratio for a binary
relationship specifies the maximum number of relationship
instances that an entity can participate in.
• The possible cardinality ratios for binary relationship types
are 1:1, l:N, N:l, and M:N.
2. Participation - It specifies whether the existence of an
entity depends on its being related to another entity via the
relationship type.
• Total participation
• Partial participation
Constraints on binary relationship
types
• 1:1
• 1:N
• M:N
• M:N
•
• Participation constraints
• It specifies whether the existence of an entity depends
on its being related to another entity via the relationship
type.
• Total participation
• Partial participation
• Strong Entity types
• Weak Entity types
• Partial key
ENTITY TYPE
RELATIONSHIP TYPE
ATTRIBUTE
KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
TOTAL PARTICIPATION OF E2 IN R
1 1
1
N
Notown Records has decided to store information about musicians who perform on
its albums
• Each musician that records at Notown has an SSN, a name, an address, and a
phone number.
• Each instrument used in songs recorded at Notown has a unique identification
number, a name (e.g., guitar, synthesizer, flute) and a musical key (e.g., C, B-flat,
E-flat).
• Each album recorded on the Notown label has a unique identification number, a
title, a copyright date, a format (e.g., CD or MC), and an album identifier.
• Each song recorded at Notown has a title and an author.
• Each musician may play several instruments, and a given instrument may be
played by several musicians.
• Each album has a number of songs on it, but no song may appear on more than
one album.
• Each song is performed by one or more musicians, and a musician may perform a
number of songs.
• Each album has exactly one musician who acts as its producer. A musician may
produce several albums, of course.
ER-to-Relational Mapping Algorithm
1. Domain constraints
2. Key constraints
3. constraints on nulls
4. Entity integrity constraints
5. Referential integrity constraints
Domain Constraints
• Domain constraints specify that within each tuple, the value of
each attribute A must be an atomic value from the domain
dom(A).
• A data type or format is also specified for each domain.
• The data types associated with domains typically include
standard numeric data types for integers (such as short integer,
integer, and long integer) and real numbers (float and double-
precision float).
• Characters, booleans, fixed-length strings, and variable-length
strings are also available, as are date, time, timestamp, and, in
some cases, money data types.
• Other possible domains may be described by a subrange of
values from a data type or as an enumerated data type in which
all possible values are explicitly listed.
Key Constraints
Superkey of R:
Is a set of attributes SK of R with the following condition:
No two tuples in any valid relation state r(R) will have the same value
for SK
That is, for any distinct tuples t1 and t2 in r(R), t1[SK] t2[SK]
This condition must hold in any valid state r(R)
Key of R:
A "minimal" superkey
That is, a key is a superkey K such that removal of any attribute from K
results in a set of attributes that is not a superkey (does not possess the
superkey uniqueness property)
Example: The STUDET relation schema:
{SSN} – key. {SSN, Name, Age)-is a superkey.
However, the superkey {SSN, Name, Age) is not a key of STUDENT,
because removing Name or Age or both from the set still leaves us with a
superkey.
A Key is a Superkey but not vice versa
Key Constraints (continued)
• Example: Consider the CAR relation schema:
• CAR(State, Reg#, SerialNo, Make, Model, Year)
• CAR has two keys:
• Key1 = {State, Reg#}
• Key2 = {SerialNo}
• Both are also superkeys of CAR
• {SerialNo, Make} is a superkey but not a key.
• In general:
• Any key is a superkey (but not vice versa)
• Any set of attributes that includes a key is a superkey
• A minimal superkey is also a key
Key Constraints (continued)
• If a relation has several candidate keys, one is chosen arbitrarily to
be the primary key.
• The primary key attributes are underlined.
• Example: Consider the CAR relation schema:
• CAR(State, Reg#, SerialNo, Make, Model, Year)
• We chose SerialNo as the primary key
• The primary key value is used to uniquely identify each tuple in a
relation
• Provides the tuple identity
• Also used to reference the tuple from another tuple
• General rule: Choose as primary key the smallest of the candidate
keys (in terms of size)
• Not always applicable – choice is sometimes subjective
Key Constraints
Relational Database Schema
• Relational Database Schema:
• A set S of relation schemas that belong to the same
database.
• S is the name of the whole database schema
• S = {R1, R2, ..., Rn} and a set of integrity constraints IC.
• R1, R2, …, Rn are the names of the individual relation
schemas within the database S
• Following slide shows a COMPANY database
schema with 6 relation schemas
COMPANY Database Schema
Relational Database State
• A relational database state DB of S is a set of relation
states DB = {r1, r2, ..., rm} such that each ri is a state of Ri
and such that the ri relation states satisfy the integrity
constraints specified in IC.
• A relational database state is sometimes called a relational
database snapshot or instance.
• We will not use the term instance since it also applies to
single tuples.
• A database state that does not meet the constraints is an
invalid state
Populated Database State
• Each relation will have many tuples in its current relation
state
• The relational database state is a union of all the individual
relation states
• Whenever the database is changed, a new state arises
• Basic operations for changing the database:
• INSERT a new tuple in a relation
• DELETE an existing tuple from a relation
• MODIFY an attribute of an existing tuple
• Next slide (Fig. 5.6) shows an example state for the
COMPANY database schema shown in Fig. 5.5.
Slide 5- 56
Populated Database State for COMPANY
Slide 5- 57
Entity Integrity
Entity Integrity:
The primary key attributes PK of each relation schema R in S
cannot have null values in any tuple of r(R).
This is because primary key values are used to identify the individual
tuples.
t[PK] null for any tuple t in r(R).
If PK has several attributes, null is not allowed in any of these
attributes.
Note: Other attributes of R may be similarly constrained to disallow
null values, even though they are not members of the primary key.
Referential Integrity
Slide 5- 70
Summary
• Presented Relational Model Concepts
• Definitions
• Characteristics of relations
• Discussed Relational Model Constraints and Relational
Database Schemas
• Domain constraints
• Key constraints
• Entity integrity
• Referential integrity
• Described the Relational Update Operations and Dealing
with Constraint Violations
In-Class Exercise
(Taken from Exercise 5.15)
Consider the following relations for a database that keeps track of student
enrollment in courses and the books adopted for each course:
STUDENT(SSN, Name, Major, Bdate)
COURSE(Course#, Cname, Dept)
ENROLL(SSN, Course#, Quarter, Grade)
BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
TEXT(Book_ISBN, Book_Title, Publisher, Author)
Draw a relational schema diagram specifying the foreign keys for this
schema.
Slide 5- 72