presentation by: tim sablik
DESCRIPTION
Database Operations on Relations. Presentation by: Tim Sablik. There are two basic types of operations that will be addressed: Unary operations are applied to only one relation. Binary operations are applied to two relations. - PowerPoint PPT PresentationTRANSCRIPT
Presentation by: Tim SablikPresentation by: Tim Sablik
There are two basic types of operations that will There are two basic types of operations that will be addressed:be addressed: Unary operations are applied to only one relation.Unary operations are applied to only one relation. Binary operations are applied to two relations.Binary operations are applied to two relations.
I will define 9 operations in this presentation: I will define 9 operations in this presentation: insert, delete, update, select, project, join, union, insert, delete, update, select, project, join, union, intersection, and difference.intersection, and difference.
This is an example of the Insert operation.This is an example of the Insert operation. Insert is a unary operation. It inserts a new tuple (row) Insert is a unary operation. It inserts a new tuple (row)
into the relation.into the relation. Ex: CIS13, “Intro to Java” was inserted into this Ex: CIS13, “Intro to Java” was inserted into this
relation.relation.
NoNo Course-Course-NameName
UnitUnit
CIS15CIS15 Intro to CIntro to C 55
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
NoNo Course-Course-NameName
UnitUnit
CIS15CIS15 Intro to CIntro to C 55
This is an example of the Delete operation.This is an example of the Delete operation. Delete is a unary operation that removes a tuple from the Delete is a unary operation that removes a tuple from the
relation.relation. Ex: CIS13 has been deleted.Ex: CIS13 has been deleted.
This is an example of the Update operation.This is an example of the Update operation. Update is a unary operation that changes the value Update is a unary operation that changes the value
of some attributes of a tuple.of some attributes of a tuple. Ex: The number of units for CIS13 has been Ex: The number of units for CIS13 has been
updated from 5 to 4.updated from 5 to 4.
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 44
CIS15CIS15 Intro to CIntro to C 55
This is an example of the Select operation.This is an example of the Select operation. Select is a unary operation that uses some criteria to Select is a unary operation that uses some criteria to
select some of the tuples from one relation and create select some of the tuples from one relation and create a new relation.a new relation.
Ex: Only the courses with 5 units were selected.Ex: Only the courses with 5 units were selected.
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
CIS19CIS19 UNIXUNIX 44
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
This is an example of the Project operation.This is an example of the Project operation. Project is a unary operation that is applied to one Project is a unary operation that is applied to one
relation and creates a new relation. The new relation relation and creates a new relation. The new relation has fewer attributes (columns) than the original, but has fewer attributes (columns) than the original, but the same number of tuples.the same number of tuples.
Ex: The “Course-name” attribute has removed, and a Ex: The “Course-name” attribute has removed, and a new two-column relationship is projected.new two-column relationship is projected.
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
CIS19CIS19 UNIXUNIX 44
NoNo UnitUnit
CIS13CIS13 55
CIS15CIS15 55
CIS19CIS19 44
This is an example of the Join operation.This is an example of the Join operation. Join is binary operation that combines two relations based on common Join is binary operation that combines two relations based on common
attributes.attributes. Ex: The common attribute used to combine these two relations is the Course Ex: The common attribute used to combine these two relations is the Course
Number. They are Joined into a relation with 4 attributes: No, Course-Number. They are Joined into a relation with 4 attributes: No, Course-Name, Unit, and Professor.Name, Unit, and Professor.
NoNo Course-Course-NameName
UnitUnit
CIS13CIS13 Intro to JavaIntro to Java 55
CIS15CIS15 Intro to CIntro to C 55
CIS19CIS19 UNIXUNIX 44
NoNo ProfessorProfessor
CIS13CIS13 LeeLee
CIS15CIS15 WalterWalter
CIS19CIS19 LuLu
NoNo Course-Course-NameName
UnitUnit ProfessorProfessor
CIS13CIS13 Intro to JavaIntro to Java 55 LeeLee
CIS15CIS15 Intro to CIntro to C 55 WalterWalter
CIS19CIS19 UNIXUNIX 44 LuLu
This is an example of the Union operation.This is an example of the Union operation. Union is a binary operation that takes two relations with the Union is a binary operation that takes two relations with the
same attributes an makes a new relation in which each tuple is same attributes an makes a new relation in which each tuple is either in the first, second, or both relations.either in the first, second, or both relations.
Ex: The Union of two relations creates one relation with all the Ex: The Union of two relations creates one relation with all the tuples, but no duplicates (John and George only appear once).tuples, but no duplicates (John and George only appear once).
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
65806580 AnneAnne SmithSmith
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
67336733 BobBob ThompsonThompson
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
65806580 AnneAnne SmithSmith
67336733 BobBob ThompsonThompson
This is an example of the Intersection operation.This is an example of the Intersection operation. Intersection is a binary operation that takes two relations that have the same Intersection is a binary operation that takes two relations that have the same
attributes and combines them into one relation. However, only tuples that attributes and combines them into one relation. However, only tuples that are in both relations are present in the new relation.are in both relations are present in the new relation.
Ex: John and George are in both original relations, so they are the only ones Ex: John and George are in both original relations, so they are the only ones in the Intersection relation.in the Intersection relation.
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
65806580 AnneAnne SmithSmith
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
67336733 BobBob ThompsonThompson
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
This is an example of the Difference operation.This is an example of the Difference operation. Difference is a binary operation that is applied to two relations with the same Difference is a binary operation that is applied to two relations with the same
attributes. It outputs a new relation with tuples that are in the first relation attributes. It outputs a new relation with tuples that are in the first relation but not in the second.but not in the second.
Ex: Anne is the only tuple in the first relation that is not in the second Ex: Anne is the only tuple in the first relation that is not in the second relation, therefore she is the only tuple in the new relation.relation, therefore she is the only tuple in the new relation.
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
67336733 BobBob ThompsonThompson
Student IDStudent ID F-NameF-Name L-NameL-Name
67546754 JohnJohn BrownBrown
56905690 GeorgeGeorge WhiteWhite
65806580 AnneAnne SmithSmithStudent IDStudent ID F-NameF-Name L-NameL-Name
65806580 AnneAnne SmithSmith