110 likes | 198 Views
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.
E N D
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. I will define 9 operations in this presentation: insert, delete, update, select, project, join, union, intersection, and difference. Types of Operations
Insert • This is an example of the Insert operation. • Insert is a unary operation. It inserts a new tuple (row) into the relation. • Ex: CIS13, “Intro to Java” was inserted into this relation.
Delete • This is an example of the Delete operation. • Delete is a unary operation that removes a tuple from the relation. • Ex: CIS13 has been deleted.
Update • This is an example of the Update operation. • Update is a unary operation that changes the value of some attributes of a tuple. • Ex: The number of units for CIS13 has been updated from 5 to 4.
Select • This is an example of the Select operation. • Select is a unary operation that uses some criteria to select some of the tuples from one relation and create a new relation. • Ex: Only the courses with 5 units were selected.
Project • This is an example of the Project operation. • Project is a unary operation that is applied to one relation and creates a new relation. The new relation has fewer attributes (columns) than the original, but the same number of tuples. • Ex: The “Course-name” attribute has removed, and a new two-column relationship is projected.
Join • This is an example of the Join operation. • Join is binary operation that combines two relations based on common attributes. • 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-Name, Unit, and Professor.
Union • This is an example of the Union operation. • Union is a binary operation that takes two relations with the same attributes an makes a new relation in which each tuple is either in the first, second, or both relations. • Ex: The Union of two relations creates one relation with all the tuples, but no duplicates (John and George only appear once).
Intersection • This is an example of the Intersection operation. • Intersection is a binary operation that takes two relations that have the same attributes and combines them into one relation. However, only tuples that 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 in the Intersection relation.
Difference • This is an example of the Difference operation. • 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 but 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.