Relational Model
Asst.Prof. Rupali Lohar
Dept. of Computer Science & Engineering
B. R. Harne College Of Engineering & Technology, Karav, Post Vangani (W Tal
Ambernath, Mumbai, Maharashtra 421503
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
2
 Relational Databases
 represent data as a collection of tables
 each row in a table represents a collection of related values
Example
Supplier S
Relational Model –
3
 Tables (relations)
 Rows (tuples)
 Columns (attributes)
 tuples
 No duplicate tuples
 Domains
Relational Data Structure
4
 Table is the Data Structure for relational model
 Relation = Table
 name of this relation is S.
 Tuple = Row
 This relation has 5 tuples
 Each tuple represents a record of one supplier, so tuples
are seldom called records also.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
Relational Data Structure
5
 Cardinality = # of rows with data in the relation
 so for S, cardinality = 5.
 Attribute = Columns or fields.
 Degree = # of columns or fields of a relation.
 The relation S has a degree of 4.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
Relational Data Structure
6
 Domain = A pool of legal values
 For example:
 For S# we have S followed by a positive number.
 For Year we might have a four digit positive number between
1000 and 2003.
 Primary Key = A unique identifier, used to identify one
specific record from among all other records.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
Relations
7
 A relation consists of 2 parts
 Heading:
 Consists of a fixed set of attributes or columns or fields.
 Body
 Consists of the tuples or rows or records.
 Time varying set, i.e., at different intervals of time
there may be different contents in the body of a
relation.
Key Properties of Relations
8
 No Duplicate tuples
 In other words, not all fields are same
 All cells have a single value
 A relation which follows this rule is said to be in the
first normal form.
Structure of Relational Database
• Basic Structure
– The relational model uses a collection of tables.
– These tables have multiple columns, and each column has a unique name called attributes.
– The set of allowed values for each attribute is called the domain of the attribute
– whether the tuples of a relation are listed in sorted order, as in Figure 1, or are unsorted,
as in Figure 2, does not matter
The account relation.
9
The account relation with unordered tuples.
Structure of Relational Database
• Database Schema
The customer relation The branch relation.. The account relation. The depositor relation.
The loan relation.
10
The borrower relation.
• Database Schema
11
12
Structure of Relational Database
• Schema Diagram
– A database schema, along with primary key and foreign key dependencies, can be
depicted pictorially by schema diagrams.
• Each relation appears as a box, with the attributes listed inside it and the relation name above
it.
• If there are primary key attributes, a horizontal line crosses the box, with the primary key
attributes listed above the line.
• Foreign key dependencies appear as arrows from the foreign key attributes of the referencing
relation to the primary key of the referenced relation.
• Schema Diagram
– Figure shows the schema diagram for our banking enterprise.
13
ER Model to Relational Model
• ER diagrams can be mapped to relational schema, that is, it is
possible to create relational schema using ER diagram. We cannot
import all the ER constraints into relational model, but an
approximate schema can be generated.
Mapping Entity
Mapping Process (Algorithm)
• Create table for each entity.
• Entity's attributes should become fields of tables with their respective
data types.
• Declare primary key.
Mapping Relationship
Mapping Process
• Create table for a relationship.
• Add the primary keys of all participating Entities as fields of table with
their respective data types.
• If relationship has any attribute, add each attribute as field of table.
• Declare a primary key composing all the primary keys of participating
entities.
• Declare all foreign key constraints.
Mapping Weak Entity Sets
Mapping Process
• Create table for weak entity set.
• Add all its attributes to table as field.
• Add the primary key of identifying entity set.
• Declare all foreign key constraints.
Mapping Hierarchical Entities
ER specialization or generalization comes in the form of hierarchical entity
sets.
Mapping Process
• Create tables for all higher-level entities.
• Create tables for lower-level entities.
• Add primary keys of higher-level entities in the table of lower-level entities.
• In lower-level tables, add all other attributes of lower-level entities.
• Declare primary key of higher-level table and the primary key for lower-
level table.
• Declare foreign key constraints.
E-R Diagram for Banking Example
depositorcustomer
customer_name customer_city
customer_street
account_number
account
branch_name
balance
loan
branch_name
loan_number amount
borrower
branch_name
branch
branch_city
assets
account_
brach
loan_
branch
1
9
Reduction of an E-R Diagram to Relational
Schemas
• Representation of Strong Entity Sets
 Example
customer
customer_name customer_city
customer_street
customer_name customer_street customer_city
2
0
The relation customer
Reduction of an E-R Diagram to Relational
Schemas
loan_pay
ment
loan payment
• Representation of Weak Entity Sets
 Example
branch_name payment_date
loan_number amount payment_number payment_amount
loan_number payment_number payment_date payment_amount
2
1
The relation payment
Reduction of an E-R Diagram to Relational
Schemas
customer depositor account
• Tabular Representation of Relationship Sets
 Example
access_date
customer_street branch_name
customer_name customer_city account_number balance
customer_name account_number access_date
8TMhrse.SrueniltaaMtioDonl,WdeIT,pSoolaspiutror
Reduction of an E-R Diagram to Relational
Schemas
• Tabular Representation of Relationship Sets
 Combination of Tables
Example : we can combine the table for
account-branch with the table for account and
require only the following two tables:
account, with attributes account-number,
balance, and branch-name
branch, with attributes branch-name,
branch-city, and assets
account_number
account
branch_name
branch_name
branch
branch_city
assets
account_
brach
balance
14Mrs. Sunita M Dol, WIT,Solapur
Reduction of an E-R Diagram to Relational
Schemas
• Composite Attributes
 We handle composite attributes by creating a separate attribute for each of
the component attributes; we do not create a separate column for the
composite attribute itself.
 Suppose address is a composite attribute of entity set customer, and the
components of address are street and city. The table generated from
customer would then contain columns address-street and address-city;
there is no separate column for address
15Mrs. Sunita M Dol, WIT,Solapur
Reduction of an E-R Diagram to Relational
Schemas
• Composite Attributes
 Example
customer_name
customer
address
phone_number
Street city
customer_name customer_street customer_city phone_number
16TMhrse.SrueniltaaMtioDonl,WcuIT,sStoolampurer
Reduction of an E-R Diagram to Relational
Schemas
• Multivalued Attributes
 For a multivalued attribute M, we create a table T with a column C that
corresponds to M and columns corresponding to the primary key of the entity
set or relationship set of which M is an attribute.
17
Reduction of an E-R Diagram to Relational
Schemas• MultivaluedAttributes
 Example: For the multivalued attribute dependent-name, we create a table
dependent-name, with columns dname, referring to the dependent-name
attribute of employee, and employee-id, representing the primary key of the
entity set employee. Each dependent of an employee is represented as a
unique row in the table.
dname employee_id
The relation dependent_name 18
Advantages of Relational Model
• Simple
• Scalable
• Structural Independence
Disadvantages of Relational Model
• Hardware Overheads: more powerful hardware computers and data
storage devices.
• Bad Design: As the relational model is very easy to design and use. So
the users don't need to know how the data is stored in order to
access it.

Relational model

  • 1.
    Relational Model Asst.Prof. RupaliLohar Dept. of Computer Science & Engineering B. R. Harne College Of Engineering & Technology, Karav, Post Vangani (W Tal Ambernath, Mumbai, Maharashtra 421503
  • 2.
    S# SNAME STATUSCITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens 2  Relational Databases  represent data as a collection of tables  each row in a table represents a collection of related values Example Supplier S
  • 3.
    Relational Model – 3 Tables (relations)  Rows (tuples)  Columns (attributes)  tuples  No duplicate tuples  Domains
  • 4.
    Relational Data Structure 4 Table is the Data Structure for relational model  Relation = Table  name of this relation is S.  Tuple = Row  This relation has 5 tuples  Each tuple represents a record of one supplier, so tuples are seldom called records also. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 5.
    Relational Data Structure 5 Cardinality = # of rows with data in the relation  so for S, cardinality = 5.  Attribute = Columns or fields.  Degree = # of columns or fields of a relation.  The relation S has a degree of 4. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 6.
    Relational Data Structure 6 Domain = A pool of legal values  For example:  For S# we have S followed by a positive number.  For Year we might have a four digit positive number between 1000 and 2003.  Primary Key = A unique identifier, used to identify one specific record from among all other records. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 7.
    Relations 7  A relationconsists of 2 parts  Heading:  Consists of a fixed set of attributes or columns or fields.  Body  Consists of the tuples or rows or records.  Time varying set, i.e., at different intervals of time there may be different contents in the body of a relation.
  • 8.
    Key Properties ofRelations 8  No Duplicate tuples  In other words, not all fields are same  All cells have a single value  A relation which follows this rule is said to be in the first normal form.
  • 9.
    Structure of RelationalDatabase • Basic Structure – The relational model uses a collection of tables. – These tables have multiple columns, and each column has a unique name called attributes. – The set of allowed values for each attribute is called the domain of the attribute – whether the tuples of a relation are listed in sorted order, as in Figure 1, or are unsorted, as in Figure 2, does not matter The account relation. 9 The account relation with unordered tuples.
  • 10.
    Structure of RelationalDatabase • Database Schema The customer relation The branch relation.. The account relation. The depositor relation. The loan relation. 10 The borrower relation.
  • 11.
  • 12.
    12 Structure of RelationalDatabase • Schema Diagram – A database schema, along with primary key and foreign key dependencies, can be depicted pictorially by schema diagrams. • Each relation appears as a box, with the attributes listed inside it and the relation name above it. • If there are primary key attributes, a horizontal line crosses the box, with the primary key attributes listed above the line. • Foreign key dependencies appear as arrows from the foreign key attributes of the referencing relation to the primary key of the referenced relation.
  • 13.
    • Schema Diagram –Figure shows the schema diagram for our banking enterprise. 13
  • 14.
    ER Model toRelational Model • ER diagrams can be mapped to relational schema, that is, it is possible to create relational schema using ER diagram. We cannot import all the ER constraints into relational model, but an approximate schema can be generated.
  • 15.
    Mapping Entity Mapping Process(Algorithm) • Create table for each entity. • Entity's attributes should become fields of tables with their respective data types. • Declare primary key.
  • 16.
    Mapping Relationship Mapping Process •Create table for a relationship. • Add the primary keys of all participating Entities as fields of table with their respective data types. • If relationship has any attribute, add each attribute as field of table. • Declare a primary key composing all the primary keys of participating entities. • Declare all foreign key constraints.
  • 17.
    Mapping Weak EntitySets Mapping Process • Create table for weak entity set. • Add all its attributes to table as field. • Add the primary key of identifying entity set. • Declare all foreign key constraints.
  • 18.
    Mapping Hierarchical Entities ERspecialization or generalization comes in the form of hierarchical entity sets. Mapping Process • Create tables for all higher-level entities. • Create tables for lower-level entities. • Add primary keys of higher-level entities in the table of lower-level entities. • In lower-level tables, add all other attributes of lower-level entities. • Declare primary key of higher-level table and the primary key for lower- level table. • Declare foreign key constraints.
  • 19.
    E-R Diagram forBanking Example depositorcustomer customer_name customer_city customer_street account_number account branch_name balance loan branch_name loan_number amount borrower branch_name branch branch_city assets account_ brach loan_ branch 1 9
  • 20.
    Reduction of anE-R Diagram to Relational Schemas • Representation of Strong Entity Sets  Example customer customer_name customer_city customer_street customer_name customer_street customer_city 2 0 The relation customer
  • 21.
    Reduction of anE-R Diagram to Relational Schemas loan_pay ment loan payment • Representation of Weak Entity Sets  Example branch_name payment_date loan_number amount payment_number payment_amount loan_number payment_number payment_date payment_amount 2 1 The relation payment
  • 22.
    Reduction of anE-R Diagram to Relational Schemas customer depositor account • Tabular Representation of Relationship Sets  Example access_date customer_street branch_name customer_name customer_city account_number balance customer_name account_number access_date 8TMhrse.SrueniltaaMtioDonl,WdeIT,pSoolaspiutror
  • 23.
    Reduction of anE-R Diagram to Relational Schemas • Tabular Representation of Relationship Sets  Combination of Tables Example : we can combine the table for account-branch with the table for account and require only the following two tables: account, with attributes account-number, balance, and branch-name branch, with attributes branch-name, branch-city, and assets account_number account branch_name branch_name branch branch_city assets account_ brach balance 14Mrs. Sunita M Dol, WIT,Solapur
  • 24.
    Reduction of anE-R Diagram to Relational Schemas • Composite Attributes  We handle composite attributes by creating a separate attribute for each of the component attributes; we do not create a separate column for the composite attribute itself.  Suppose address is a composite attribute of entity set customer, and the components of address are street and city. The table generated from customer would then contain columns address-street and address-city; there is no separate column for address 15Mrs. Sunita M Dol, WIT,Solapur
  • 25.
    Reduction of anE-R Diagram to Relational Schemas • Composite Attributes  Example customer_name customer address phone_number Street city customer_name customer_street customer_city phone_number 16TMhrse.SrueniltaaMtioDonl,WcuIT,sStoolampurer
  • 26.
    Reduction of anE-R Diagram to Relational Schemas • Multivalued Attributes  For a multivalued attribute M, we create a table T with a column C that corresponds to M and columns corresponding to the primary key of the entity set or relationship set of which M is an attribute. 17
  • 27.
    Reduction of anE-R Diagram to Relational Schemas• MultivaluedAttributes  Example: For the multivalued attribute dependent-name, we create a table dependent-name, with columns dname, referring to the dependent-name attribute of employee, and employee-id, representing the primary key of the entity set employee. Each dependent of an employee is represented as a unique row in the table. dname employee_id The relation dependent_name 18
  • 28.
    Advantages of RelationalModel • Simple • Scalable • Structural Independence Disadvantages of Relational Model • Hardware Overheads: more powerful hardware computers and data storage devices. • Bad Design: As the relational model is very easy to design and use. So the users don't need to know how the data is stored in order to access it.