SlideShare a Scribd company logo
1 of 35
Fundamental of Database System
Chapter Two: Relational Model
Prepared By Fanta T.
Mettu University
1/25/2024 1
Contents of Chapter two
 Data model
 Relational Model
 Constraints
 Relational Constraints
 Relational Integrity
 Key constraints
 Referential constraints
1/25/2024 2
Data model
 A specific DBMS has its own specific Data Definition Language, but this
type of language is too low level to describe the data requirements of
an organization in a way that is readily understandable by a variety of
users a higher-level language which is called data-model is needed
 The main purpose of Data Model is to represent the data in an
understandable way.
 Data Model: a set of concepts to describe the structure of a database,
and certain constraints that the database should obey.
 Data model is a description of the way that data is stored in a
database.
 Data model helps to understand the relationship between entities and
to create the most effective structure to hold data.
3
Data model …
 Data Model is a collection of tools or concepts for
describing.
 Data
 Data relationships
 Data semantics
 Data constraints
 Categories/types of data models include:
 Record-based
 Object-based
 Physical
4
Record-based Data Models
 Represent data by using record/tabular structures
and hence are called record‐based data models.
 Record-based Data Models Consist of a number of
fixed format records.
 Each record type defines a fixed number of fields
with fixed length.
 Types of Record-based Data Model
 Hierarchical Data Model
 Network Data Model
 Relational Data Model
5
Hierarchical Data Model
 The simplest data model
 The hierarchical data model organizes data in a upside
down tree structure
 Record type is referred to as node or segment
 The top node is the root node
 A parent node can have more than one child node
 A child node can only have one parent node
 The relationship between parent and child is one-to-
many
6
Hierarchical Data Model
7
Network Model
 In the network model, the entities are organized in a
graph, in which some entities can be accessed
through several paths
8
Relational model
 In the relational model, data is organized in two-
dimensional tables( row & column) called relations
 A row of the table is called tuple/record
 A column of a table is called attribute/field
 Data value is the value of the Attribute
9
Relational model
10
.
Relational Data model
11
Properties of Relational Databases
1.Two dimensional structure composed of rows and Columns.
2. Each row(tuple) and Column(attribute) are a unique.
3. all values in a column must match with a column data type.
4. each table must have a primary key: no null, no duplicate.
E.g Employee table
1/25/2024 12
EmpNo ENAME JOB Salary
100 tola lecturer 20000
101 Chala Manager 30000
102 Tamirat Accountant 200000
Properties of Relational Databases
 Each row of a table is uniquely identified by a
PRIMARY KEY composed of one or more columns
 Each tuple in a relation must be unique
 Group of columns, that uniquely identifies a row in
a table is called a CANDIDATE KEY
 ENTITY INTEGRITY RULE of the model states that
no component of the primary key may contain a
NULL value.
 A column or combination of columns that matches
the primary key of another table is called a
FOREIGN KEY. Used to cross-reference tables.
13
1/25/2024 14
Primary Key – It is a special key which uniquely identifies each record in a table.
Foreign Key – It establishes a link between records in two different tables in a
database.
Definition: Foreign key is a field in the table that is the primary key in another table.
Properties of Relational Databases…
 The REFERENTIAL INTEGRITY RULE of the model
states that, for every foreign key value in a table
there must be a corresponding primary key value
in another table in the database or it should be
NULL
 A table is either a BASE TABLES (Named Relations)
or VIEWS (Unnamed Relations)
 Only Base Tables are physically stores
 VIEWS are derived from BASE TABLES with SQL
instructions like: [SELECT .. FROM .. WHERE ..
ORDER BY]
15
Properties of Relational Databases…
 DB is the collection of tables
 Each entity in one table
 Attributes are fields (columns) in table
 Order of rows and columns is immaterial
 Entries with repeating groups are said to be un-
normalized
 Entries are single-valued
 Each column (field or attribute) has a distinct
name
16
Properties of Relational Databases
17
Building Blocks of the Relational Data Model
The building blocks of the relational data model are:
 Entities: real world physical or logical object
 Attributes: properties used to describe each Entity
or real world object.
 Relationship: the association between Entities
 Constraints: rules that should be obeyed while
manipulating the data.
18
Entities
Things or object in real world with independent
existence.
 An entity is object with:
 physical existence : person, car, house,
employed, etc.
 conceptual existence : job, course, event
 The name given to an entity should always be a
singular noun descriptive of each item to be
stored in it.
 E.g.: student NOT students.
19
Attribute
Attribute is a certain characteristics of entity
Named column/field of relation.
 Example : an EMPLOYEE entity maybe
describe by employee's name, age, address,
salary and job.
 Used to hold information about the objects
to be represented in database.
20
Types of Attributes
(1) Simple (atomic) Vs Composite attributes
 Simple: contains a single value (not divided into sub
parts) E.g. Age, gender
 Composite: Divided into sub parts (composed of other
attributes) E.g. Name, address
(2) Single-valued Vs multi-valued attributes
 Single-valued: have only single value(the value may
change but has only one value at one time)
E.g. Name, Sex, Id. No. color_of_eyes
 Multi-Valued: have more than one value
E.g. Address, certificate
21
Types of Attributes…
(3) Stored vs. Derived Attribute
 Stored : not possible to derive or compute
E.g. Name, Address
 Derived: The value may be derived (computed)
from the values of other attributes.
E.g. Age (current year – year of birth)
Length of employment (current date- start date)
Profit (earning-cost)
G.P.A (grade point/credit hours)
22
Types of Attributes…
(4) Null Values
 In some cases, particular entity may not have an
applicable value for an attribute.
 Two cases:
1. The attribute value is missing.
E.g.: Height attribute is NULL.
2. It is not known whether the attribute value exist.
E.g.: College degree – some people may have it
and some not.
 You may enter the value NA (meaning not
applicable)
 Value of a key attribute can not be null.
23
Entity versus Attributes
When designing the conceptual specification of the database,
one should pay attention to the distinction between an Entity
and an Attribute.
 Consider designing a database of employees for an
organization:
 Should address be an attribute of Employees or an entity
(connected to Employees by a relationship)?
 If we have several addresses per employee, address must
be an entity (attributes cannot be set-valued/multi valued)
 If the structure (city, Woreda, Kebele, etc) is important,
e.g. want to retrieve employees in a given city, address
must be modeled as an entity (attribute values are atomic)
24
Relationship
 An association between entities.
 RELATIONSHIP, one can talk about the Number of
Entities and the Number of Tuples participating in the
association.
 These two concepts are called DEGREE and
CARDINALITY of a relationship respectively.
Degree of a Relationship
 Degree of a relationship is the number of entity types
involved. The n-ary relationship is the general form for
 degree n. Special cases are unary, binary, and ternary
,where the degree is 1, 2, and 3, respectively
25
Relationship...
Among the Degrees of relationship, the following are the
basic:
 UNARY/RECURSIVE RELATIONSHIP: An employee ia a
manager of another employee
 BINARY RELATIONSHIPS: An employee works-for
department
 TERNARY RELATIONSHIP: customer purchase item
from a shop keeper
 And a generalized one: N-NARY RELATIONSHIP: Tuples
from arbitrary number of entity sets are participating in
a relationship
26
Cardinality of a Relationship
 Another important concept about relationship is the
number of instances/tuples that can be associated with a
single instance from one entity in a single relationship.
 The number of instances participating or associated with a
single instance from an entity in a relationship is called the
CARDINALITY of the relationship.
 The major cardinalities of a relationship are:
 One –To- One (1:1):one tuple is associated with only
one other tuple.
E.g. Building – Location  as a single building will be
located in a single location and as a single location will
only accommodate a single Building
27
Cardinality of a Relationship…
 One –To- Many (1:M): one tuple can be associated with many
many other tuples, but not the reverse
E.g. Department-Student
 Many –To- One (M:1) many tuples are associated with one
tuple but not the reverse
E.g. Employee – Department: as many employees belong to a
single department.
 Many to Many (M:N): one tuple is associated with many other
tuples and from the other side, with a different role name one
tuple will be associated with many tuples
E.g. Student – Course  as a student can take many
courses and a single course can be attended by many
students.
28
Relational Constraints/Integrity Rules
 Relational Integrity
 Domain Integrity: No value of the attribute should be
beyond the allowable limits
 Entity Integrity: In a base relation, no attribute of a
Primary Key can assume a value of NULL
 Referential Integrity: If a Foreign Key exists in a
relation, either the Foreign Key value must match a
Candidate Key value in its home relation or the Foreign
Key value must be NULL
 Enterprise Integrity: Additional rules specified by the
users or database administrators of a database are
incorporated
29
Key constraints
If tuples are need to be unique in the database, and then
we need to make each tuple distinct. To do this we need to
have relational keys that uniquely identify each relation.
1. Primary Key
 Is an attributes that uniquely identify each rows.
 Each table must have primary key.
 Cannot be NULL value to maintain Entity Integrity.
Eg: studentID for Table Students
2. Candidate key
 A candidate key is a single field or the least combination
of fields that uniquely identifies each record in the
table. There can be more than one candidate keys in a
relation. It is Uniqueness and Irreducibility 30
Key constraints…
3. Alternate/secondary key: An alternate key is any
candidate key that is not primary key.
4. Foreign Key: Attribute is an attributes whose value
match the primary key values in related tables.
 It Creates a relationship between relations
31
Relational Views
 Relations are perceived as a Table from the users’
perspective. Actually, there are two kinds of relation in
relational database.
 The two categories or types of Relations are Named
and Unnamed Relations.
 The basic difference is on how the relation is created,
used and updated:
1. Base Relation: A Named Relation corresponding to an
entity in the conceptual schema, whose tuples are
physically stored in the database.
32
Relational Views…
2. View/Unnamed Relation/virtually derived relation:
 A View is the dynamic result of one or more relational
operations operating on the base relations to produce
another virtual relation that does not actually exist as
presented.
 Purpose of a view
 Hides unnecessary information from users: since
only part of the base relation (Some collection of
attributes, not necessarily all) are to be included in
the virtual table.
 Provide powerful flexibility and security: since
unnecessary information will be hidden from the
user there will be some sort of data security.
33
Relational Schema vs Instance
Schema is a set of attribute and domain name pairs
defined by named relation/entity.
 Relation Name (attribute_1, attribute_2,….attribute_n)
 E.g. EMPLOYEE { SSN, FNAME, LNAME, MINIT, BDATE,
ADDRESS, SEX, SALARY, SUPERSSN, DNO }
 The primary key is underlined.
Instance is a tuple at a specific moment of time
 E.g.: Branch (BranchNo, Street, City, PostalCode )
 The relation instance for branch is:
 (B005, 55 Jln Dobi, Johor Bahru, 80100)
 (B006, 55 Jalan Perai, Johor Bahru, 80000)
 The relation instance change when tuple is updated,
deleted or inserted. 34
Group discussion
Create a relational database schema and
Instance of your department
35

More Related Content

Similar to Download different material from slide share

Data Models & Introduction to UML
Data Models & Introduction to UML Data Models & Introduction to UML
Data Models & Introduction to UML نبيله نواز
 
Week 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data ModelWeek 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data Modeloudesign
 
3. Chapter Three.pdf
3. Chapter Three.pdf3. Chapter Three.pdf
3. Chapter Three.pdffikadumola
 
Introduction to database-ER Model
Introduction to database-ER ModelIntroduction to database-ER Model
Introduction to database-ER ModelAjit Nayak
 
entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptIRWANBINISMAILKPMGur1
 
Data resource management
Data resource managementData resource management
Data resource managementNirajan Silwal
 
erdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdferdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdfvinayakjadhav94
 
5e7ry754.pptx
5e7ry754.pptx5e7ry754.pptx
5e7ry754.pptxqwert001
 
ER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSRubal Sagwal
 
Module 2 dbms.pptx
Module 2 dbms.pptxModule 2 dbms.pptx
Module 2 dbms.pptxVijishK
 

Similar to Download different material from slide share (20)

Data Models & Introduction to UML
Data Models & Introduction to UML Data Models & Introduction to UML
Data Models & Introduction to UML
 
Week 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data ModelWeek 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data Model
 
3. Chapter Three.pdf
3. Chapter Three.pdf3. Chapter Three.pdf
3. Chapter Three.pdf
 
DBMS Part-2.pptx
DBMS Part-2.pptxDBMS Part-2.pptx
DBMS Part-2.pptx
 
ERD(2).ppt
ERD(2).pptERD(2).ppt
ERD(2).ppt
 
Introduction to database-ER Model
Introduction to database-ER ModelIntroduction to database-ER Model
Introduction to database-ER Model
 
entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
 
Data resource management
Data resource managementData resource management
Data resource management
 
dbms mannual.pdf
dbms mannual.pdfdbms mannual.pdf
dbms mannual.pdf
 
Sq lite module3
Sq lite module3Sq lite module3
Sq lite module3
 
erdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdferdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdf
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 
database
databasedatabase
database
 
ERD.pptx
ERD.pptxERD.pptx
ERD.pptx
 
5e7ry754.pptx
5e7ry754.pptx5e7ry754.pptx
5e7ry754.pptx
 
ER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMS
 
Computer sec2-1st term
Computer sec2-1st termComputer sec2-1st term
Computer sec2-1st term
 
Module 2 dbms.pptx
Module 2 dbms.pptxModule 2 dbms.pptx
Module 2 dbms.pptx
 
Lecture one db
Lecture one dbLecture one db
Lecture one db
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Download different material from slide share

  • 1. Fundamental of Database System Chapter Two: Relational Model Prepared By Fanta T. Mettu University 1/25/2024 1
  • 2. Contents of Chapter two  Data model  Relational Model  Constraints  Relational Constraints  Relational Integrity  Key constraints  Referential constraints 1/25/2024 2
  • 3. Data model  A specific DBMS has its own specific Data Definition Language, but this type of language is too low level to describe the data requirements of an organization in a way that is readily understandable by a variety of users a higher-level language which is called data-model is needed  The main purpose of Data Model is to represent the data in an understandable way.  Data Model: a set of concepts to describe the structure of a database, and certain constraints that the database should obey.  Data model is a description of the way that data is stored in a database.  Data model helps to understand the relationship between entities and to create the most effective structure to hold data. 3
  • 4. Data model …  Data Model is a collection of tools or concepts for describing.  Data  Data relationships  Data semantics  Data constraints  Categories/types of data models include:  Record-based  Object-based  Physical 4
  • 5. Record-based Data Models  Represent data by using record/tabular structures and hence are called record‐based data models.  Record-based Data Models Consist of a number of fixed format records.  Each record type defines a fixed number of fields with fixed length.  Types of Record-based Data Model  Hierarchical Data Model  Network Data Model  Relational Data Model 5
  • 6. Hierarchical Data Model  The simplest data model  The hierarchical data model organizes data in a upside down tree structure  Record type is referred to as node or segment  The top node is the root node  A parent node can have more than one child node  A child node can only have one parent node  The relationship between parent and child is one-to- many 6
  • 8. Network Model  In the network model, the entities are organized in a graph, in which some entities can be accessed through several paths 8
  • 9. Relational model  In the relational model, data is organized in two- dimensional tables( row & column) called relations  A row of the table is called tuple/record  A column of a table is called attribute/field  Data value is the value of the Attribute 9
  • 12. Properties of Relational Databases 1.Two dimensional structure composed of rows and Columns. 2. Each row(tuple) and Column(attribute) are a unique. 3. all values in a column must match with a column data type. 4. each table must have a primary key: no null, no duplicate. E.g Employee table 1/25/2024 12 EmpNo ENAME JOB Salary 100 tola lecturer 20000 101 Chala Manager 30000 102 Tamirat Accountant 200000
  • 13. Properties of Relational Databases  Each row of a table is uniquely identified by a PRIMARY KEY composed of one or more columns  Each tuple in a relation must be unique  Group of columns, that uniquely identifies a row in a table is called a CANDIDATE KEY  ENTITY INTEGRITY RULE of the model states that no component of the primary key may contain a NULL value.  A column or combination of columns that matches the primary key of another table is called a FOREIGN KEY. Used to cross-reference tables. 13
  • 14. 1/25/2024 14 Primary Key – It is a special key which uniquely identifies each record in a table. Foreign Key – It establishes a link between records in two different tables in a database. Definition: Foreign key is a field in the table that is the primary key in another table.
  • 15. Properties of Relational Databases…  The REFERENTIAL INTEGRITY RULE of the model states that, for every foreign key value in a table there must be a corresponding primary key value in another table in the database or it should be NULL  A table is either a BASE TABLES (Named Relations) or VIEWS (Unnamed Relations)  Only Base Tables are physically stores  VIEWS are derived from BASE TABLES with SQL instructions like: [SELECT .. FROM .. WHERE .. ORDER BY] 15
  • 16. Properties of Relational Databases…  DB is the collection of tables  Each entity in one table  Attributes are fields (columns) in table  Order of rows and columns is immaterial  Entries with repeating groups are said to be un- normalized  Entries are single-valued  Each column (field or attribute) has a distinct name 16
  • 17. Properties of Relational Databases 17
  • 18. Building Blocks of the Relational Data Model The building blocks of the relational data model are:  Entities: real world physical or logical object  Attributes: properties used to describe each Entity or real world object.  Relationship: the association between Entities  Constraints: rules that should be obeyed while manipulating the data. 18
  • 19. Entities Things or object in real world with independent existence.  An entity is object with:  physical existence : person, car, house, employed, etc.  conceptual existence : job, course, event  The name given to an entity should always be a singular noun descriptive of each item to be stored in it.  E.g.: student NOT students. 19
  • 20. Attribute Attribute is a certain characteristics of entity Named column/field of relation.  Example : an EMPLOYEE entity maybe describe by employee's name, age, address, salary and job.  Used to hold information about the objects to be represented in database. 20
  • 21. Types of Attributes (1) Simple (atomic) Vs Composite attributes  Simple: contains a single value (not divided into sub parts) E.g. Age, gender  Composite: Divided into sub parts (composed of other attributes) E.g. Name, address (2) Single-valued Vs multi-valued attributes  Single-valued: have only single value(the value may change but has only one value at one time) E.g. Name, Sex, Id. No. color_of_eyes  Multi-Valued: have more than one value E.g. Address, certificate 21
  • 22. Types of Attributes… (3) Stored vs. Derived Attribute  Stored : not possible to derive or compute E.g. Name, Address  Derived: The value may be derived (computed) from the values of other attributes. E.g. Age (current year – year of birth) Length of employment (current date- start date) Profit (earning-cost) G.P.A (grade point/credit hours) 22
  • 23. Types of Attributes… (4) Null Values  In some cases, particular entity may not have an applicable value for an attribute.  Two cases: 1. The attribute value is missing. E.g.: Height attribute is NULL. 2. It is not known whether the attribute value exist. E.g.: College degree – some people may have it and some not.  You may enter the value NA (meaning not applicable)  Value of a key attribute can not be null. 23
  • 24. Entity versus Attributes When designing the conceptual specification of the database, one should pay attention to the distinction between an Entity and an Attribute.  Consider designing a database of employees for an organization:  Should address be an attribute of Employees or an entity (connected to Employees by a relationship)?  If we have several addresses per employee, address must be an entity (attributes cannot be set-valued/multi valued)  If the structure (city, Woreda, Kebele, etc) is important, e.g. want to retrieve employees in a given city, address must be modeled as an entity (attribute values are atomic) 24
  • 25. Relationship  An association between entities.  RELATIONSHIP, one can talk about the Number of Entities and the Number of Tuples participating in the association.  These two concepts are called DEGREE and CARDINALITY of a relationship respectively. Degree of a Relationship  Degree of a relationship is the number of entity types involved. The n-ary relationship is the general form for  degree n. Special cases are unary, binary, and ternary ,where the degree is 1, 2, and 3, respectively 25
  • 26. Relationship... Among the Degrees of relationship, the following are the basic:  UNARY/RECURSIVE RELATIONSHIP: An employee ia a manager of another employee  BINARY RELATIONSHIPS: An employee works-for department  TERNARY RELATIONSHIP: customer purchase item from a shop keeper  And a generalized one: N-NARY RELATIONSHIP: Tuples from arbitrary number of entity sets are participating in a relationship 26
  • 27. Cardinality of a Relationship  Another important concept about relationship is the number of instances/tuples that can be associated with a single instance from one entity in a single relationship.  The number of instances participating or associated with a single instance from an entity in a relationship is called the CARDINALITY of the relationship.  The major cardinalities of a relationship are:  One –To- One (1:1):one tuple is associated with only one other tuple. E.g. Building – Location  as a single building will be located in a single location and as a single location will only accommodate a single Building 27
  • 28. Cardinality of a Relationship…  One –To- Many (1:M): one tuple can be associated with many many other tuples, but not the reverse E.g. Department-Student  Many –To- One (M:1) many tuples are associated with one tuple but not the reverse E.g. Employee – Department: as many employees belong to a single department.  Many to Many (M:N): one tuple is associated with many other tuples and from the other side, with a different role name one tuple will be associated with many tuples E.g. Student – Course  as a student can take many courses and a single course can be attended by many students. 28
  • 29. Relational Constraints/Integrity Rules  Relational Integrity  Domain Integrity: No value of the attribute should be beyond the allowable limits  Entity Integrity: In a base relation, no attribute of a Primary Key can assume a value of NULL  Referential Integrity: If a Foreign Key exists in a relation, either the Foreign Key value must match a Candidate Key value in its home relation or the Foreign Key value must be NULL  Enterprise Integrity: Additional rules specified by the users or database administrators of a database are incorporated 29
  • 30. Key constraints If tuples are need to be unique in the database, and then we need to make each tuple distinct. To do this we need to have relational keys that uniquely identify each relation. 1. Primary Key  Is an attributes that uniquely identify each rows.  Each table must have primary key.  Cannot be NULL value to maintain Entity Integrity. Eg: studentID for Table Students 2. Candidate key  A candidate key is a single field or the least combination of fields that uniquely identifies each record in the table. There can be more than one candidate keys in a relation. It is Uniqueness and Irreducibility 30
  • 31. Key constraints… 3. Alternate/secondary key: An alternate key is any candidate key that is not primary key. 4. Foreign Key: Attribute is an attributes whose value match the primary key values in related tables.  It Creates a relationship between relations 31
  • 32. Relational Views  Relations are perceived as a Table from the users’ perspective. Actually, there are two kinds of relation in relational database.  The two categories or types of Relations are Named and Unnamed Relations.  The basic difference is on how the relation is created, used and updated: 1. Base Relation: A Named Relation corresponding to an entity in the conceptual schema, whose tuples are physically stored in the database. 32
  • 33. Relational Views… 2. View/Unnamed Relation/virtually derived relation:  A View is the dynamic result of one or more relational operations operating on the base relations to produce another virtual relation that does not actually exist as presented.  Purpose of a view  Hides unnecessary information from users: since only part of the base relation (Some collection of attributes, not necessarily all) are to be included in the virtual table.  Provide powerful flexibility and security: since unnecessary information will be hidden from the user there will be some sort of data security. 33
  • 34. Relational Schema vs Instance Schema is a set of attribute and domain name pairs defined by named relation/entity.  Relation Name (attribute_1, attribute_2,….attribute_n)  E.g. EMPLOYEE { SSN, FNAME, LNAME, MINIT, BDATE, ADDRESS, SEX, SALARY, SUPERSSN, DNO }  The primary key is underlined. Instance is a tuple at a specific moment of time  E.g.: Branch (BranchNo, Street, City, PostalCode )  The relation instance for branch is:  (B005, 55 Jln Dobi, Johor Bahru, 80100)  (B006, 55 Jalan Perai, Johor Bahru, 80000)  The relation instance change when tuple is updated, deleted or inserted. 34
  • 35. Group discussion Create a relational database schema and Instance of your department 35