0% found this document useful (0 votes)
18 views

Week 4 - Databse Design Using Relational Model

The document discusses relational database design and the relational model. It covers topics like database schema, relation schema and instance, attributes, keys, and how to represent entity sets and relationships in relational databases.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Week 4 - Databse Design Using Relational Model

The document discusses relational database design and the relational model. It covers topics like database schema, relation schema and instance, attributes, keys, and how to represent entity sets and relationships in relational databases.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Week 4 : ERD Relational Model

ER Diagram
Outline
Reducing ER Diagrams to Relational Schemas
Extended E-R Features

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 2


Reduction to Relational Schemas
• For each entity set and relationship set in the database design, there
is a unique relation schema to which we assign the name of the
corresponding entity set or relationship set.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 3


Representation of Strong Entity Sets with
Simple Attributes.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 4


Representation of Strong Entity Sets with
Complex Attributes.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 5


Representation of Strong Entity Sets with
Multivalued Attributes.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 6


10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 7
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 8
Specialization (Top-Down)
• For instance, a subset of entities within an entity set may have
attributes that are not shared by all the entities in the entity set.
• As an example, the entity set person may be further classified as one
of the following:
• employee.
• student.
• Employee entities may be described further by the attribute salary,
whereas student entities may be described further by the attribute
tot cred. The process of designating subgroupings within an entity set
is called specialization.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 9
Generalization (Bottom-Up)
• There are similarities between the instructor entity set and the
secretary entity set in the sense that they have several attributes that
are conceptually the same across the two entity sets: namely, the
identifier, name, and salary attributes. This commonality can be
expressed by generalization.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 10


10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 11
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 12
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 13
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 14
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 15
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 16
Overlapping and Disjoint Specialization
• The way we depict specialization in an E-R diagram depends on
whether an entity may belong to multiple specialized entity sets
or if it must belong to at most one specialized entity set. The
former case (multiple sets permitted) is called overlapping
specialization, while the latter case (at most one permitted) is
called disjoint specialization.
• For an overlapping specialization (as is the case for student and
employee as specializations of person), two separate arrows are
used. For a disjoint specialization (as is the case for instructor and
secretary as specializations of employees), a single arrow is used.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 17
Aggregation
• Now, suppose that each instructor guiding a student on a project is
required to file a monthly evaluation report. We model the evaluation
report as an entity evaluation, with a primary key evaluation id.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 18


10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 19
Aggregation
• Now, suppose that each instructor guiding a student on a project is
required to file a monthly evaluation report. We model the evaluation
report as an entity evaluation, with a primary key evaluation id.

• It appears that the relationship sets proj_guide and eval for can be
combined into one single relationship set. Nevertheless, we should
not combine them into a single relationship since some instructor,
student, and project combinations may not have an associated
evaluation.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 20


Aggregation
• There is redundant information in the resultant figure; however, since
every instructor, student, and project combination in eval for must
also be in proj_guide. If the evaluation were a value rather than an
entity, we could instead make evaluation a multivalued composite
attribute of the relationship set proj_guide.
• However, this alternative may not be an option if an evaluation may
also be related to other entities; for example, each evaluation report
may be associated with a secretary responsible for further processing
the evaluation report to make scholarship payments.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 21


Aggregation
• The best way to model a situation such as the one just described is to use
aggregation.
• Aggregation is an abstraction through which relationships are treated as
higher-level entities.
• For example, we regard the relationship set proj_guide (relating the entity
sets instructor, student, and project) as a higher-level entity set called
proj_guide.
• Such an entity set is treated in the same manner as any other entity set.
• We can then create a binary relationship eval_for between proj_guide and
evaluation to represent which (student, project, instructor) combination an
evaluation is for.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 22
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 23
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 24
Symbols used in the E-R notation

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 25


Symbols used in the E-R notation

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 26


Symbols used in the E-R notation

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 27


Alternative E-R Notations

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 28


Alternative E-R Notations

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 29


Week 4 : Relational Model
Relational Database Design Model
Outline
Structure of Relational Databases
Database Schema
Keys
Schema Diagrams

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 31


Structure of Relational Databases attributes
(or columns)
• A relational database
consists of a collection of tuples
tables, each assigned a (or rows)
unique name.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 32


Structure of Relational Databases
• In general, a row in a table represents a relationship among a set of
values. Since a table is a collection of such relationships, there is a close
correspondence between the concept of a table and the mathematical
concept of relation, from which the relational data model takes its
name.
• A relationship between n values is represented mathematically by an n-
tuple of values, i.e., a tuple with n values, which corresponds to a row in
a table.
• Thus, in the relational model the term relation is used to refer to a
table, while the term tuple is used to refer to a row. Similarly, the term
attribute refers to a column of a table.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 33
Relation Schema and Instance
• Database schema is the logical design of the database, and the database instance
is a snapshot of the data in the database at a given instant in time.
A1, A2, …, An are attributes
R = (A1, A2, …, An ) is a relation schema
Example:
instructor = (ID, name, dept_name, salary)
• A relation instance r defined over schema R is denoted by r (R).
• A table specifies the current values in a relation.
• An element t of relation r is called a tuple and is represented by a row in a table
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 34
Attributes
• The set of allowed values for each attribute is called the domain of
the attribute
• Attribute values are (normally) required to be atomic; that is,
indivisible
• An attribute that cannot be divided further into meaningful
subcomponents/sub-attributes is an Atomic attribute. Person name non atomi
• The special value null is a member of every domain. Indicated that
the value is “unknown”
• The null value causes complications in the definition of many
operations
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 35
Relations are Unordered
• Order of tuples is irrelevant (tuples
may be stored in an arbitrary order)
• Example: instructor relation with
unordered tuples

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 36


Database Schema
Example Instance:
• Database schema -- is the logical
structure of the database.
• Database instance -- is a
snapshot of the data in the
database at a given time.
• Example: schema: instructor
(ID, name, dept_name, salary)

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 37


Keys
• We must have a way to specify how tuples within a given relation are
distinguished. This is expressed in terms of their attributes.
• A superkey is a set of one or more attributes that, taken collectively,
allow us to identify a tuple in the relation uniquely.
• For example, the ID attribute of the relation instructor is sufficient to
distinguish one instructor tuple from another. Thus, ID is a superkey.
On the other hand, the instructor's name attribute is not a superkey
because several instructors might have the same name.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 38


Keys
• Keys play an important role in the relational database.
• It is used to uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.
• For example, ID is used as a key in the Student table because it is unique for each
student. In the PERSON table, passport_number, license_number, SSN are keys
since they are unique for each person.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 39


Super Key
• Super key is an attribute set that
can uniquely identify a tuple. For
which no proper subset is super
key. A super key is a superset of a
candidate key.
• For example: In the above
EMPLOYEE table, for(EMPLOEE_ID,
EMPLOYEE_NAME), the name of
two employees can be the same,
but their EMPLYEE_ID can't be the
same. Hence, this combination can
also be a key.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 40
Candidate key
• A candidate key is an attribute or
attribute that uniquely identifies a
tuple.
• Except for the primary key, the
remaining attributes are considered a
candidate key. The candidate keys are
as strong as the primary key.
• For example, it is best suited for the
primary key in the EMPLOYEE table.
The other attributes, like SSN,
Passport_Number, License_Number,
etc., are considered candidate keys.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 41
Primary key
• It is the first key used to identify one and only
one instance of an entity uniquely. An entity
can contain multiple keys, as we saw in the
PERSON table. The key which is most suitable
from those lists becomes a primary key.
• In the EMPLOYEE table, ID can be the primary
key since it is unique for each employee. In
the EMPLOYEE table, we can even select
License_Number and Passport_Number as
primary keys since they are also unique.
• For each entity, the primary key selection is
based on requirements and developers.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 42


Rules for defining Primary key
• Two rows can’t have the same primary key value
• It must for every row to have a primary key value.
• The primary key field cannot be null.
• The value in a primary key column can never be modified or updated
if any foreign key refers to that primary key.

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 43


Foreign key
• Foreign keys are the column of the table used to point to the primary
key of another table.
• Every employee works in a specific department in a company, and the
employee and department are two different entities. So, we can't
store the department's information in the employee table. That's why
we link these two tables through the primary key of one table.
• We add the primary key of the DEPARTMENT table, Department_Id,
as a new attribute in the EMPLOYEE table.
• In the EMPLOYEE table, Department_Id is the foreign key, and both
the tables are related.
10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 44
Foreign key

10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 45


10/05/2024 Dept. of CSE, SCSE, Manipal University Jaipur 46

You might also like