+ All Categories
Home > Documents > n-ary Relations and Their Applications

n-ary Relations and Their Applications

Date post: 25-Feb-2016
Category:
Upload: howell
View: 71 times
Download: 2 times
Share this document with a friend
Description:
n-ary Relations and Their Applications. Rosen 8.2. n-ary relations. We can have relation between more than just 2 sets. A binary relation involves 2 sets and can be described by a set of pairs A ternary relation involves 3 sets and can be described by a set of triples … - PowerPoint PPT Presentation
Popular Tags:
20
n-ary Relations and Their Applications Rosen 8.2
Transcript
Page 1: n-ary Relations and Their Applications

n-ary Relations and Their Applications

Rosen 8.2

Page 2: n-ary Relations and Their Applications

n-ary relations

We can have relation between more than just 2 sets

A binary relation involves 2 sets and can be described by a set of pairsA ternary relation involves 3 sets and can be described by a set of triples…

An n-ary relation involves n sets and can be described by a set of n-tuples

Relations are used to represent computer databases

Also used to represent constraints!

Page 3: n-ary Relations and Their Applications

n-ary relations n-ary Relations

ndomainsAAA

AAAaryn

AAA

n

n

n

isrelation theof degree Therelation theof theare ,,, sets The

product cartesian theofsubset a isrelation An

sets be ,,Let

21

21

2,1

Page 4: n-ary Relations and Their Applications

n-ary relations n-ary Relations

cbacbaNNNR

such that ),,( triplesof consisting on relation thebe Let

Note: N is the set of natural numbers {0,1,2,3,…}

An example

}),3,2,1(,),4,2,0(),3,2,0(,),3,1,0(),2,1,0{( R

R)3,4,2(

Note: R could be considered as an extensional representation of the ternary relation a<b<c, assuming domains are finite and really quite small

The relation has degree 3

The domains of the relation are the set of natural numbers

Page 5: n-ary Relations and Their Applications

n-ary relations n-ary Relations

)0()(such that ),,,(tuples-4 of consisting on relation thebe Let

dcbadcbadcbaZNZNR

Note: N is the set of natural numbers {0,1,2,3,…} Z is the set of integers {…,-2,-1,0,1,2,…}

An example

Note: R could be considered as an extensional representation of the ternary relation a<b<c, assuming domains are finite and really quite small

The relation has degree 4RRR

)9,3,6,6()3,3,11,5(

)0,1,1,0(

Page 6: n-ary Relations and Their Applications

Relational databases

Database is made up of records.Typical operations on a database are

• find records that satisfy a given criteria• delete records• add records• update records

Some everyday databases• student records• health records• tax information• telephone directories• banking records• …

Databases may be represented using the relational model

Page 7: n-ary Relations and Their Applications
Page 8: n-ary Relations and Their Applications
Page 9: n-ary Relations and Their Applications

Relational databases The relational data model

Database made up of records, they are n-tuples, made up of fields

Student record might look as follows

(name,metricNo,faculty,gpa)

(Jones,200401986,Arts,4.9)(Lee,200408972,Science,3.6)(Kuhns,200501728,Humanities,5.0)(Moore,200308327,Science,5.5)

relations (in relDB) also called tables

gpa is an attribute

Page 10: n-ary Relations and Their Applications

Relational databases The relational data model

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

Example from the book

Attributes: name, metric No, Dept and GPA

Page 11: n-ary Relations and Their Applications

Relational databases The relational data model

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

primary key:An attribute/domain/column is a primary key whenthe value of this attribute uniquely defines tuplesi.e. no two tuples have the same value for that attribute

Name cannot be a primary key, neither can Dept or GPSmetricNo is a primary key

Page 12: n-ary Relations and Their Applications

Relational databases The relational data model

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

The current collection of n-tuples (records) in the relation (table)is called the extension of the relation

The permanent aspects of the relation (table) such as the attribute namesis called the intention of the relation

Page 13: n-ary Relations and Their Applications

Relational databases The relational data model

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

A composite key is a combination of attributesThat uniquely define tuples

Page 14: n-ary Relations and Their Applications

Relational databases Operations on n-ary relations

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

CRtuplesnarynRS

RCarynR

c

condition esatisfy th that from all ofrelation new the to maps operator selection The

satisfy.must in elementsthat condition a andrelation an be Let

Selection

Page 15: n-ary Relations and Their Applications

Relational databases Operations on n-ary relations

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

CRtuplesnarynRS

RCarynR

c

condition esatisfy th that from all ofrelation new the to maps operator selection The

satisfy.must in elementsthat condition a andrelation an be Let

Selection

3.45GPA condition theis where operator selection Apply theCSc

3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou

3.88ScienceComputer 231455AckermannGPADeptmetricNoName

Page 16: n-ary Relations and Their Applications

Relational databases Operations on n-ary relations

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

Projection

nmaaatuplemaaatuplen

iiiPprojection

m

m

iii

n

miii

where),,,( the to),,,( themaps

where The

21

21

21

21

It strips out specific columns

Page 17: n-ary Relations and Their Applications

Relational databases Operations on n-ary relations

2.99Psychology786576Stevens3.90sMathematic678543Rao3.49sMathematic453876Goodfriend3.49ScienceComputer 102147Chou3.45Physics888323Adams3.88ScienceComputer 231455AckermannGPADeptmetricNoName

Projection

nmaaatuplemaaatuplen

iiiPprojection

m

m

iii

n

miii

where),,,( the to),,,( themaps

where The

21

21

21

21

4,1 projection Apply the P

2.99Stevens3.90Rao3.49Goodfriend3.49Chou3.45Adams3.88AckermannGPAName

Page 18: n-ary Relations and Their Applications

Relational databases Operations on n-ary relationsJoin

Joins two tables/relations together, matching up on specific attributes

575sMathematic518ScienceComputer 551Physics544Physics617Psychology501Psychology412Zoology335Zoology

RosenRosenGrammerGrammerFaberFaberCruzCruz

CourseDeptLecturer

08.00A100412Zoology09.00A100335Zoology11.00A110617Psychology15.00A100501Psychology16.00B505544Physics16.00N521611sMathematic15.00N502575sMathematic14.00N521518ScienceComputer TimeRoomCourseDept

4)Defn p.534Rosen (seematch attributes goverlappin the where from come attributes last theand come attributes first thesuch that

degree ofrelation new a delivers and andly respective

relations and are and where),(operator join The

pSpnRpm

pnmnpmp

arynarymSRSRJ p

Page 19: n-ary Relations and Their Applications

Relational databases Operations on n-ary relationsJoin

R

RosenRosenGrammerGrammerFaberFaberCruzCruz

CourseDeptLecturer

Relation

575sMathematic518ScienceComputer 551Physics544Physics617Psychology501Psychology412Zoology335Zoology

S

TimeRoomCourseDept

Relation

08.00A100412Zoology09.00A100335Zoology11.00A110617Psychology15.00A100501Psychology16.00B505544Physics16.00N521611sMathematic15.00N502575sMathematic14.00N521518ScienceComputer

),(2 SRJ

15.00N502575sMathematicRosen14.00N521518ScienceComputer Rosen16.00B505544PhysicsGrammer11.00A110617PsychologyFaber15.00A100501PsychologyFaber08.00A100412ZoologyCruz09.00A100335ZoologyCruzTimeRoomCourseDeptLecturer

Page 20: n-ary Relations and Their Applications

Explain the previous slide

Explain how what we do differs from what will be presented in IM2


Recommended