Relational Operators: Follow the form: Such as Which selects (π

advertisement
Relational Operators:
Follow the form:
𝑜𝑝𝑒𝑟𝑎𝑡𝑜𝑟𝑠𝑝𝑒𝑐𝑖𝑓𝑖𝑐𝑎𝑡𝑖𝑜𝑛 (𝑅𝑒𝑙𝑎𝑡𝑖𝑜𝑛𝑠)
Such as
𝛑𝑓𝑖𝑟𝑠𝑡𝑁𝑎𝑚𝑒,𝑖𝑑 (𝑆𝑡𝑢𝑑𝑒𝑛𝑡)
Which selects (π) only the ‘firstName’ and ‘id’ columns from a table/relation called
Student
π (lower-case pi):
Projection—Extract columns from a relation (See above example)
ρ (lower-case rho):
Rename—Renames an attribute (column header) or a relation; unary operator
Attribute: 𝛒𝑛𝑒𝑤𝐴𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑁𝑎𝑚𝑒/𝑜𝑙𝑑𝐴𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑁𝑎𝑚𝑒 (𝑅𝑒𝑙𝑎𝑡𝑖𝑜𝑛)
OR
Relation: 𝛒𝑛𝑒𝑤𝑅𝑒𝑙𝑎𝑡𝑖𝑜𝑛𝑁𝑎𝑚𝑒 (𝑅𝑒𝑙𝑎𝑡𝑖𝑜𝑛)
σ (lower-case sigma):
Selection—Selects rows from a relation, given a condition is met
Additional Operators:
X (upper-case X):
Cartesian (cross) Product—All combinations among the tuples of each table
∪ (union, set operator):
Union—Merges two tables under shared attributes, with identical domains.
- (minus sign):
Difference—Everything in the first table that is not in the second table
Consider the following tables:
Student
id
1234
7268
5678
9961
3005
fiName
Alice
Tom
Sue
Juan
Alexi
Teacher
instructor
Max
Constance
Laurence
Paula
Bob
id
1785
2894
3780
9902
1123
GradTA
fiName
Steve
Jane
Bob
id
6674
1788
1123
laName
Smith
Smith
Rogers
Aiza
Benedict
course
Sie550
Sie550
Sie509
Cos220
Mat127
grade
4.0
3.4
3.4
3.8
2.6
instructor
Max
Max
Constance
Laurence
Paula
Answer the following:
1. What are the valid candidate keys for table Student? Which is the better choice for a
primary key? Why
2. Give an example of a composite key for table Student. What reasons are there for
using a composite key?
3. Attribute ‘course’ utilizes the data type ‘VARCHAR(6)’ which is a string of
letters/numbers/symbols up to 6 characters long. Is this representative of the domain
of course (given normal expectations)? Why or why not?
Provide the result tuples for the following:
4. 𝛑<𝑓𝑖𝑁𝑎𝑚𝑒,𝑖𝑑> (𝑆𝑡𝑢𝑑𝑒𝑛𝑡)
5. 𝛔𝑔𝑟𝑎𝑑𝑒 >3.5 (𝑆𝑡𝑢𝑑𝑒𝑛𝑡)
6. 𝛑 𝑖𝑑 (𝛔𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑜𝑟=𝑀𝑎𝑥 (𝑆𝑡𝑢𝑑𝑒𝑛𝑡))
7. 𝛒𝑝𝑟𝑜𝑓𝑒𝑠𝑠𝑜𝑟 (Teacher – GradTA)
8. 𝛑<𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑜𝑟,𝑖𝑑> (Student) ∪ GradTA
9. 𝛒𝑒𝑑𝑢𝑐𝑎𝑡𝑜𝑟 (Teacher ∪ GradTA)
Provide the relational algebra notation for the following queries, and show their output tuples:
10. A relation displaying the first and last names of all students enrolled in SIE courses,
called SIEstudents
11. A relation showing the id and last name of students where last name is Smith
12. The intersection of Teacher and GradTA. Think critically, how can we reproduce an
intersection operation with the tools we currently have? Hint: You will use differance.
Download