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

FDB CH 3

Chapter 3 of the document discusses Database Modeling, focusing on the Entity-Relationship (E-R) Model, which was developed by Peter Chen in 1976. It explains the components of E-R diagrams, including entities, attributes, and relationships, and their significance in database design. The chapter also covers the relational data model, its concepts, and constraints that ensure data integrity and consistency.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

FDB CH 3

Chapter 3 of the document discusses Database Modeling, focusing on the Entity-Relationship (E-R) Model, which was developed by Peter Chen in 1976. It explains the components of E-R diagrams, including entities, attributes, and relationships, and their significance in database design. The chapter also covers the relational data model, its concepts, and constraints that ensure data integrity and consistency.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Fundamentals of Database System

Chapter 3

Database Modeling

10/28/2024 Prepared By: Mr. Dereje A. 1


Entity Relationship (E-R) Model
 It was developed by Peter Chen in 1976.
 It generates an abstract diagram that can be helpful in designing a relational database.
 It contains three main components such as entities, attributes and relationships
 It is the most widely used conceptual level tool.
 It represents the overall logical structure of a database graphically.
 It can be represented by using an ER diagram
 It is simple and understandable model.
 It also has an advantage in that it is capable of being normalized.
 It has variations such as the Enhanced ER Model and the Object Relationship Model.
 It explains the relationship among the entities present in the database.
 It used to model real-world objects like a person, a car, or a company and the relation between these
real-world objects.
 In short, the ER Diagram or ER model is the structural format of the database.

10/28/2024 Prepared By: Mr. Dereje A. 2


Why We Use ER Diagrams in DBMS
 They represent real world entities which are easy to convert into relations (tables).
 They provide the purpose of real-world modeling of objects which makes them intently useful.
 They require no technical knowledge and no hardware support.
 They are very easy to understand and easy to create even for a naive user.
 They give a standard solution for visualizing the data logically.
 Generally, they used for
 Conceptual simplicity
 Visual representation
 Easy Database design
 Effective communication Tool between database actors
 Identifying redundancy and inconsistencies
 Fast Database maintenance
 High flexibility
 Database optimization
10/28/2024 Prepared By: Mr. Dereje A. 3
Symbols Used in E-R Diagram
 It used to model the logical view of the system from a data perspective which consists of these symbols:
 Rectangles: Rectangles represent Entities in the ER Model.
 Ellipses: Ellipses represent Attributes in the ER Model.
 Diamond: Diamonds represent Relationships among Entities.
 Lines: Lines represent attributes to entities and entity sets with other relationship types.
 Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
 Double Rectangle: Double Rectangle represents a Weak Entity.

Rectangle
Ellipse
Diamond
Line
Double
Ellipse
Ellipse with
internal line
10/28/2024 Prepared By: Mr. Dereje A. 4
General Symbols Used in E-R Diagram

10/28/2024 Prepared By: Mr. Dereje A. 5


Components of E-R Diagram
 An E-R Diagram is made up of three main components:
→ Entity
→ Relationship
→ Attribute

10/28/2024 Prepared By: Mr. Dereje A. 6


Components of E-R Diagram
Entity
 It is a physical thing or an object in the real world with an independent existence.
 It can be represented using the rectangle-shaped box
 It is named using singular nouns.
 It will be the Table in Relational Database.
 E.g. Car, Employee, Student, Department, etc.
Entity Set:
 A collection of similar entities(e.g. all employees).
 All entities have the same set of attributes.
E.g. Student entity set=>collection of all student entities.

10/28/2024 Prepared By: Mr. Dereje A. 7


Components of E-R Diagram
Entity Types
 Strong entity
 It exists on its own and act as owner entity
 Also called identifying or owner entity type (Parent/Dominant Entity)
 It is represented by using solid rectangle.
 It does not depend on any other entities for it to exist.
 It has a primary key, that helps in identifying it uniquely
 Primary key can be represented by solid underlined line

10/28/2024 Prepared By: Mr. Dereje A. 8


Components of E-R Diagram
Weak Entity
 It has always a total participating constraint because they cannot be identified without an owner entity.
 It exists with the existence of other strong entities
 It can be represented by using double rectangle.
 Also called child entity type or subordinate entity type
 It has weak relationship with strong entity
 Normally, it has partial key (discriminator)
 Partial key are set of attributes that can uniquely identify weak entities that are related to some owner entity
 Partial key attribute is denoted with dotted underlined line.
 Weak Relationship is a relationship between Weak and Strong Entities
 Strong Relationship is a relationship between two strong Entities

10/28/2024 Prepared By: Mr. Dereje A. 9


Components of E-R Diagram
Attributes
 Particular properties that describe an entity.
 They are individual bits of data that make up an entity
 They are represented using ellipse-shaped figures.
 Every elliptical figure represents one attribute and is directly connected to its
entity
 They will be columns in the table.
 E.g. Student has attributes like name, age, address, salary etc.

10/28/2024 Prepared By: Mr. Dereje A. 10


Components of E-R Diagram
Attribute Types
 Key Attribute
 Uniquely define each entity in a data set
 Super key
 One or more attributes used to uniquely identify all attributes in a relation.
 All super keys can’t be candidate keys but the reverse is true.
 In relation, a number of super keys is more than a number of candidate keys.
 Candidate key
 The simplest possible super key
 Used to uniquely identify the tuples in relation or table.
 Can contain a NULL value which opposes to the primary key.
 there is more than one candidate key that can take place in a relationship
 No attributes within a candidate key can be a super key in itself.
 Primary key
 The candidate key is chosen to uniquely define an entity set.
 No two entries in a database might share the same primary key value=>Uniqueness
 In an ER diagram, primary key will be underlined.
 Any entity containing a primary key is considered a strong entity.
 Foreign key
 It identifies one entity’s relationship to another.
 Weak entities rely on foreign keys to define them as strong entities.
10/28/2024 Prepared By: Mr. Dereje A. 11
Components of E-R Diagram
Attribute Types
 Key Attribute
 Uniquely define each entity in a data set

10/28/2024 Prepared By: Mr. Dereje A. 12


Components of E-R Diagram
Attribute Type=> Key Attribute

10/28/2024 Prepared By: Mr. Dereje A. 13


Components of E-R Diagram
Attribute Types
 Composite
 can be divided into smaller subparts
 composed of many other attributes
 represented by an ellipse, and those ellipses are connected with an ellipse
 E.g. Name {Fname, Mname, Lname}

10/28/2024 Prepared By: Mr. Dereje A. 14


Components of E-R Diagram
Attribute Types
 Single or atomic valued
 takes up only a single value for each entity instance.
 E.g.. Age, ID, etc.
 Multi-valued
 contains a set of values
 takes up more than a single value for each entity instance
 It is represented by double ellipse.
 E.g. A person degree, mobile number, email, car color
 Derived
 They are calculated based on other attributes
 dependent on some other attributes
 Represented by dashed ellipse.
 E.g.. Age, Circle Area
 Stored
 They are physically stored in the database
 E.g.. Birth date

10/28/2024 Prepared By: Mr. Dereje A. 15


E-R Diagram Example

10/28/2024 Prepared By: Mr. Dereje A. 16


Relationships and Its Type
 Relationships depict the connections or associations between entities or tables.
 They are represented by diamond-shaped boxes.
 They are labeled using verbs such as “teaches”, “enrolls”, “registers”, “works”, “manages”, etc.
 They can have cardinality and participation constraints.
 They are key element in relational database design
 Achieved using a primary key and a foreign key.
 Enables users to run queries for related data across multiple tables.

10/28/2024 Prepared By: Mr. Dereje A. 17


Cardinality of Relationships
Four types of relationships(Cardinality Ratio):-
1. One-to-one ('1:1‘):
Each row in one table corresponds to exactly one row in another table.
 It is less common
 Eg. Country and Capital city
2. One-to-many ('1:N‘):
 A single row in one table corresponds to multiple rows in another table.
 It is the most common type of relationship.
 Eg. mother and children.
3. Many-to-one('N:1'):
 has multiple entries on one side and a single entry on the other end.
 Eg. children and mother .
4. Many-to-many(N:N):
 Many rows in one table can correspond to multiple rows in another table and vice versa.
 Eg Student – Course .

10/28/2024 Prepared By: Mr. Dereje A. 18


Degree of Relationships
 A relationship may consist of many entities.
 The number of entity sets or participants that are participated (associated) in that relationship is
Degree of relationships.
 Based on the degree, the relationships may be identified as
1. Unary or Recursive (degree 1)
 both the associating entity types are the same
 In a relation only one entity set is participating

2. binary (degree 2)

3. ternary (degree 3) and

4. N-ary (Has n types of entities)


10/28/2024 Prepared By: Mr. Dereje A. 19
How Are Relationships Established?
 The following are some of them:-
1. Primary key - a unique identifier for each record in a table
Characteristics of a Primary Key
 Uniqueness: The primary key must contain unique values.
No two records can have the same primary key value.
 Not-null: The primary key cannot contain NULL values.
Every record must have a value for the primary key.
 Immutability: The value of the primary key should not change over time.
It should remain constant throughout the life of the record.
 Minimality: The primary key should consist of the minimum number of attributes.
2. Foreign key - A column whose values reference the primary key of another table.
3. Candidate keys:- There may have many candidates, among which one candidate key can be
selected as a primary key.

10/28/2024 Prepared By: Mr. Dereje A. 20


The Relational Data Model
 It is based on the concept of a Relation.
 A Relation is a mathematical concept based on the ideas of sets.
 It comes from the formal foundation provided by the theory of relations.
 It represents the database as a collection of relations.
 A relation is nothing but a table of values.
 Every row in the table represents a collection of related data values.
 These rows in the table denote a real-world entity or relationship.
 Data are stored as tables.
 However, the physical storage of the data is independent of the way the data are logically
organized.

10/28/2024 Prepared By: Mr. Dereje A. 21


The Relational Data Model
INFORMAL DEFINITIONS

 RELATION: A table of values


 A relation may be thought of as a set of rows.
 A relation may alternately be though of as a set of columns.
 Each row represents a fact that corresponds to a real-world entity or
relationship.
 Each row has a value of an item or set of items that uniquely identifies
that row in the table.
 Sometimes row-ids or sequential numbers are assigned to identify the
rows in the table.
 Each column typically is called by its column name or column header or
attribute name.

10/28/2024 Prepared By: Mr. Dereje A. 22


The Relational Data Model
FORMAL DEFINITIONS
 A Relation may be defined in multiple ways.
 The Schema of a Relation: R (A1, A2, .....An)
Relation schema R is defined over attributes A1, A2, .....An
For Example -
CUSTOMER (Cust-id, Cust-name, Address, Phone#)
 Here, CUSTOMER is a relation defined over the four attributes Cust-id,
Cust-name, Address, Phone#, each of which has a domain or a set of
valid values. For example, the domain of Cust-id is 6 digit numbers.

10/28/2024 Prepared By: Mr. Dereje A. 23


The Relational Data Model
FORMAL DEFINITIONS
 A tuple is an ordered set of values (rows).
 Each value is derived from an appropriate domain.
 Each row in the CUSTOMER table may be referred to as a tuple in the
table and would consist of four values.
 <632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404)
894-2000"> is a tuple belonging to the CUSTOMER relation.
 A relation may be regarded as a set of tuples (rows).
 Columns in a table are also called attributes of the relation.

10/28/2024 Prepared By: Mr. Dereje A. 24


The Relational Data Model
DEFINITIONS EXAMPLES

10/28/2024 Prepared By: Mr. Dereje A. 25


The Relational Data Model
DEFINITIONS SUMMARY

10/28/2024 Prepared By: Mr. Dereje A. 26


Relational Data Model Concepts
Attribute:
 Each column in a Table. The # of columns=> Degree
 Attributes are the properties which define a relation.
 E.g., Student_Rollno, NAME,etc.
Tables
 Relations are saved in the table format.
 It is stored along with its entities.
 A table has two properties rows and columns.
 Rows represent records and columns represent attributes.
Tuple
 It is nothing but a single row of a table, which contains a single record.
Relation Schema
 A relation schema represents the name of the relation with its attributes.
Degree:
 The total number of attributes(Columns) which in the relation is called the degree of the relation.
10/28/2024 Prepared By: Mr. Dereje A. 27
Relational Data Model Concepts
Cardinality:
 Total number of rows present in the Table.
Column
 The column represents the set of values for a specific attribute.
Relation instance
 Relation instance is a finite set of tuples in the RDBMS system.
 Relation instances never have duplicate tuples.
Relation key
 Every row has one, two or multiple attributes, which is called relation key.
Attribute domain
 Every attribute has some pre-defined value and scope which is known as attribute domain

10/28/2024 Prepared By: Mr. Dereje A. 28


Relational Constraints
Constraints
 are rules or conditions that are applied to the data within a database.
 help to ensure data integrity, consistency, and adherence to business rules.

1. Domain Constraints
 Every domain must contain atomic values, which means composite and multivalued attributes are not
allowed.
 If we assign the datatype of attribute age as int, we can’t give it values other than int datatype.
 The value of the attribute must be available in the corresponding domain.

10/28/2024 Prepared By: Mr. Dereje A. 29


Relational Integrity Constraints
2. Key or Uniqueness Constraints
 A relation may have multiple candidate keys.
 Then, one has to be chosen as primary key.

10/28/2024 Prepared By: Mr. Dereje A. 30


Relational Integrity Constraints
3. Entity Integrity Constraints
 Refers that no primary key can take Null Value
 This is because primary key values are used to identify the individual tuples.
 t[PK]  null for any tuple t in r(R)
 A table can contain a null value other than the primary key field.
 A primary key must be unique and null value in the relational table.

10/28/2024 Prepared By: Mr. Dereje A. 31


Relational Integrity Constraints
4. Referential Integrity Constraints
 Used to maintain the consistency among the tuples in two relations
 This constraint is enforced or kept through foreign key
 The foreign key in one table should be the primary key of another table

10/28/2024 Prepared By: Mr. Dereje A. 32


Bank E-R Diagram Example

10/28/2024 Prepared By: Mr. Dereje A. 33


Enhanced E-R Diagram

Reading Assignment

10/28/2024 Prepared By: Mr. Dereje A. 34


10/28/2024 Prepared By: Mr.Dereje A. 35

You might also like