30
Logical Database Design Converting ER diagrams to Relational Schema Chapter-3

3.Relational Model

Embed Size (px)

Citation preview

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 130

Logical Database Design

Converting ER diagrams to Relational

Schema

Chapter-3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 230

Introduction

bull The entire database and more particularly

the modern database uses a very

important data model called as theRelational Model

bull This model was proposed by Codd in the

year 1970 During that time the popular

models were only Network model and

Hierarchical model

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 330

Logical database design

bull Process of converting the conceptual model into an

equivalent representation in the implementation

model (relationalhierarchicnetwork etc)

bull We will focus on the relational model

Relational database design

bull Convert ER model into relational schema (a specification of the table definitions and their foreign key links)

bull There are well defined rules for this conversion

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 430

Relation

bull The relational model represents the databaseas a collection of relations Each relation

resembles a simple table having a set of rows

and set of columnsbull Each relation consists of a relational schema and

relational instance The instance is nothing but a

relation having a set of specific values for the

records in the database at a particular time

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 530

Example

Name RegNo Addr Phone DBirth GPA

Prasad 1BI99CS045 456 Koramangala 5567234 23-Mar-67 89

Gaurav 1BI98CS012 2 JC Road 6623109 10-Dec-66 45

Ayswaria 1BI97CS044 12 KS Layout 6669456 04-Aug-65 90

BrName BrCity Assets

VV Puram Bangalore 10034567

JC Road Mysore 2390156

Jayanagar Bangalore 6784560

MG Road Belgaum 12445566

Gandhinagar Belgaum 67888888

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 630

Relation - Definition

bullA relation R is a subset of the Cartesian product of the domains that define R

R (dom(A1)) (dom(A2)) (dom(An))

This actually gives the total number of tuples inthe Cartesian product R is represented as R (A1

A2 An)

bullThe degree of a relation is the number of attributes that a relation has and the cardinality of

the relation instance is the number of tuples in it

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 230

Introduction

bull The entire database and more particularly

the modern database uses a very

important data model called as theRelational Model

bull This model was proposed by Codd in the

year 1970 During that time the popular

models were only Network model and

Hierarchical model

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 330

Logical database design

bull Process of converting the conceptual model into an

equivalent representation in the implementation

model (relationalhierarchicnetwork etc)

bull We will focus on the relational model

Relational database design

bull Convert ER model into relational schema (a specification of the table definitions and their foreign key links)

bull There are well defined rules for this conversion

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 430

Relation

bull The relational model represents the databaseas a collection of relations Each relation

resembles a simple table having a set of rows

and set of columnsbull Each relation consists of a relational schema and

relational instance The instance is nothing but a

relation having a set of specific values for the

records in the database at a particular time

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 530

Example

Name RegNo Addr Phone DBirth GPA

Prasad 1BI99CS045 456 Koramangala 5567234 23-Mar-67 89

Gaurav 1BI98CS012 2 JC Road 6623109 10-Dec-66 45

Ayswaria 1BI97CS044 12 KS Layout 6669456 04-Aug-65 90

BrName BrCity Assets

VV Puram Bangalore 10034567

JC Road Mysore 2390156

Jayanagar Bangalore 6784560

MG Road Belgaum 12445566

Gandhinagar Belgaum 67888888

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 630

Relation - Definition

bullA relation R is a subset of the Cartesian product of the domains that define R

R (dom(A1)) (dom(A2)) (dom(An))

This actually gives the total number of tuples inthe Cartesian product R is represented as R (A1

A2 An)

bullThe degree of a relation is the number of attributes that a relation has and the cardinality of

the relation instance is the number of tuples in it

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 330

Logical database design

bull Process of converting the conceptual model into an

equivalent representation in the implementation

model (relationalhierarchicnetwork etc)

bull We will focus on the relational model

Relational database design

bull Convert ER model into relational schema (a specification of the table definitions and their foreign key links)

bull There are well defined rules for this conversion

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 430

Relation

bull The relational model represents the databaseas a collection of relations Each relation

resembles a simple table having a set of rows

and set of columnsbull Each relation consists of a relational schema and

relational instance The instance is nothing but a

relation having a set of specific values for the

records in the database at a particular time

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 530

Example

Name RegNo Addr Phone DBirth GPA

Prasad 1BI99CS045 456 Koramangala 5567234 23-Mar-67 89

Gaurav 1BI98CS012 2 JC Road 6623109 10-Dec-66 45

Ayswaria 1BI97CS044 12 KS Layout 6669456 04-Aug-65 90

BrName BrCity Assets

VV Puram Bangalore 10034567

JC Road Mysore 2390156

Jayanagar Bangalore 6784560

MG Road Belgaum 12445566

Gandhinagar Belgaum 67888888

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 630

Relation - Definition

bullA relation R is a subset of the Cartesian product of the domains that define R

R (dom(A1)) (dom(A2)) (dom(An))

This actually gives the total number of tuples inthe Cartesian product R is represented as R (A1

A2 An)

bullThe degree of a relation is the number of attributes that a relation has and the cardinality of

the relation instance is the number of tuples in it

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 430

Relation

bull The relational model represents the databaseas a collection of relations Each relation

resembles a simple table having a set of rows

and set of columnsbull Each relation consists of a relational schema and

relational instance The instance is nothing but a

relation having a set of specific values for the

records in the database at a particular time

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 530

Example

Name RegNo Addr Phone DBirth GPA

Prasad 1BI99CS045 456 Koramangala 5567234 23-Mar-67 89

Gaurav 1BI98CS012 2 JC Road 6623109 10-Dec-66 45

Ayswaria 1BI97CS044 12 KS Layout 6669456 04-Aug-65 90

BrName BrCity Assets

VV Puram Bangalore 10034567

JC Road Mysore 2390156

Jayanagar Bangalore 6784560

MG Road Belgaum 12445566

Gandhinagar Belgaum 67888888

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 630

Relation - Definition

bullA relation R is a subset of the Cartesian product of the domains that define R

R (dom(A1)) (dom(A2)) (dom(An))

This actually gives the total number of tuples inthe Cartesian product R is represented as R (A1

A2 An)

bullThe degree of a relation is the number of attributes that a relation has and the cardinality of

the relation instance is the number of tuples in it

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 530

Example

Name RegNo Addr Phone DBirth GPA

Prasad 1BI99CS045 456 Koramangala 5567234 23-Mar-67 89

Gaurav 1BI98CS012 2 JC Road 6623109 10-Dec-66 45

Ayswaria 1BI97CS044 12 KS Layout 6669456 04-Aug-65 90

BrName BrCity Assets

VV Puram Bangalore 10034567

JC Road Mysore 2390156

Jayanagar Bangalore 6784560

MG Road Belgaum 12445566

Gandhinagar Belgaum 67888888

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 630

Relation - Definition

bullA relation R is a subset of the Cartesian product of the domains that define R

R (dom(A1)) (dom(A2)) (dom(An))

This actually gives the total number of tuples inthe Cartesian product R is represented as R (A1

A2 An)

bullThe degree of a relation is the number of attributes that a relation has and the cardinality of

the relation instance is the number of tuples in it

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 630

Relation - Definition

bullA relation R is a subset of the Cartesian product of the domains that define R

R (dom(A1)) (dom(A2)) (dom(An))

This actually gives the total number of tuples inthe Cartesian product R is represented as R (A1

A2 An)

bullThe degree of a relation is the number of attributes that a relation has and the cardinality of

the relation instance is the number of tuples in it

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 730

RELATIONAL MODEL

CONSTRAINTS

bull An integrity constraint is a restriction specified

on a database schema

bull The term integrity refers to the accuracy orcorrectness of data in the database

bull Example an attribute Marks in a Student

relation can take values only from 0 to 100

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 830

Domain Constraints

bull The domain constraints specifies the value of

each attribute A that must be an atomic value

from the domain dom (A)bull Example The type integer may hold all the

integer values may be allowed Oracle allows

VARCHAR2 NUMBER CHAR INTEGERDATE LONG RAW LONG RAW BLOB

CLOB BFILE

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 930

Key Constraints

bull A key constraint is a declaration to specify a minimal set of attributes to find a tuple uniquely in a relation

Candidate Key Definition

Let K be a set of attributes of the relation R Then K is a candidate

key if and only if it satisfies the following two conditions

(1) Uniqueness No legal values of R ever contain two distinct tuples

with the same value

(2) Irreducibility No proper subset of K has the uniqueness property

Eg-1 Sid Name is not a candidate key because this set properly

contains the key Sid

Eg-2 BranchName BranchCity is not a candidate key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1030

Key Constraints

bull Super Key

A superset of a candidate key is a super key A super key has the uniqueness property but not necessarily theirreducible property

Eg Sid Name is a super key bull Primary Key

It is customary to have one of the candidate keys as theprimary key of the relation It is better to choose a primary

key with minimal set of attributesEg SSN RegNo PartNo etc

Can the subset CFirstName CLastName CPhone form aprimary key

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1130

Key Constraintsbull Foreign Key

A foreign key is a set of attributes of a relation say R2 whose

values are required to match values of some primary key of some

other relation R1 The foreign key constraint is necessary between

any two relations to maintain the data consistency

Eg Employees(SSN Name DNo )

Departments( DNumber DName)

DNo in Employees relation is called as foreign key

bull What happens when insertion deletion or modification is done to

the records with the enforced constraints

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1230

Converting ER diagrams to relational

schema

bullConverting Entity intoRELATIONTable

bullConverting Attributes into Column ortable

bullConverting Relationships into Attributes

or tables

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1330

Converting Attributes to

Columnsbull Each single-valued attribute becomes a column

bull Derived attributes are ignored

bull Composite attributes are represented by components

bull Multi-valued attributes are represented by a

separate tablebull The key attribute of the entity type becomes the

primary key of the table

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1430

ER to Relational mapping

bull Strong Entity to Table

For every strong entity E create a table R that includes all thesimple attributes of E

Employees(SSNNameBDateAddrSexSalary)

Employees

SSN

Addr

Name Sex

Salary

BDate

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1530

Entity example

bull Address is a composite attribute

bull Years of service is a derived attribute(calculated from DOJ amp current date)

bull Skill set is a multi-valued attribute

bull Employee (E Name Door_No Street City Pincode

Date_Of_Joining)

Emp_Skillset( E Skillset)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1630

Converting weak entity types

bullWeak entity types are converted into a table of their own with the primary key of the strong entity acting as a foreign

key in the table

bull This foreign key along with the key of the weak entity form the

composite primary key of this table

The Relational Schema

Employee ( E helliphellip)

Dependant ( E D_Name AddressREL)

E_NAME

E

SAL

REL

ADDR

D_NAME

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1730

Converting Relationships

The way relationships are represented depends on thecardinality and the degree of the relationship

The possible cardinalities are

bull 11 1M NM

The degrees are

bull Unary bull Binary

bull Ternary hellip

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1830

Unary 11

bullConsider employees who are

also a couplebullThe primary key field itself will

become foreign key in the sametable

Employee( E Name Married_to )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 1930

Unary 1N

bullThe primary key field itself will become foreign key

in the same tablebullSame as unary 11

Employee( E NamehellipManager )FKPK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2030

Unary MN

bull There will be two resulting tables

bull One to represent the entity and another to represent the MNrelationship

bull Employee( E Namehellip)

bull Guarantor_of ( Guarantor E Beneficiary E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2130

Binary 11

bull Case 1Combination of participation types

bull The primary key of the partial participant(EMPLOYEE)

will become the foreign key of the total participantbull Employee( E Namehellip)

bull Department ( Dept Namehellip E_Head )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2230

Binary 11

Case 2 Uniform Participation types

The primary key of either of the participants can become a

foreign key in the other

bull Employee ( Enamehellip)bull Chair( item model location used_by ) (or)

bull Employee ( E NamehellipSits_on )

bull Chair (itemhellip)

1 1

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2330

Binary 1N

The primary key of the relation on the ldquo1rdquo side of therelationship becomes a foreign key in the relation on

the ldquoNrdquo side

bull Teacher (ID Name Telephone )

bull Subject (Code Name Teacher_ID )

FK

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2430

Binary MN

bull A new table is created to represent the relationship

bull Contains two foreign keys ndash one from each of the participants in the relationship

bull The primary key of the new table is the combination of

the two foreign keys

Book ( Acc Titlehellip)

Employee (ENamehellip)

Issue (Book E )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2530

Many-to-Many cardinality

SSN

Name

Addr

M N

Hours

Works_O

n

Employees

PNumbere

r

PName

PLocation

Projects

Works_On (SSN PNo Hours)

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2630

Ternary relationship

bull Ternary relationship represented by a new table bull The new table contains three foreign keys -

one from each of the participating Entities

bull The primary key of the new table is thecombination of all three foreign keys

bull Prescription ( Doctor Patient Medicine_Name )

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2730

bull Each multi valued attribute should be translated

into a table Then the primary key for this table

is nothing but the primary key of the participating entity

DNumber DLocation

1 Bangalore

2 Belgaum

3 Bangalore

2 ChennaiDepartments

DNumberer

DName

Locations

Handling multi valued attribute

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2830

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 2930

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3

7312019 3Relational Model

httpslidepdfcomreaderfull3relational-model 3030

End of Chapter 3