60 likes | 83 Views
A relation R1 consisting of a bunch of attributes. A relation R2 consisting of a bunch of attributes. Find all possible keys. Find sets of R2’s attributes that are primary keys in other relations. A bunch of n candidate keys. Foreign keys. Pick a winner. One primary Key.
E N D
A relation R1 consisting of a bunch of attributes A relation R2 consisting of a bunch of attributes Find all possible keys Find sets of R2’s attributes that are primary keys in other relations A bunch of n candidate keys Foreign keys Pick a winner One primary Key Overview of Various Kinds of Keys • How many foreign keys can a relation have? • Can a foreign key of R be the primary key of R itself? • Is a primary key still a candidate key? Department of Computer Science and Engineering, HKUST Slide 1
Questions • Selection on R • Project on R • R1 join R2 • Exists • For All • R1 intersect/union/difference R2 Can I answer the following queries by checking a single row in the table or a pair of rows in two tables (in case the operation has two operands)? R1 R2 Department of Computer Science and Engineering, HKUST Slide 2
t t[amount]>1200? Summary of Key Concepts (about Tuple Relational Calculus) t loan • t is a tuple variable which can hold a tuple of loan t[amount]: is the value under the salary attribute What is the difference between t[salary] and the salary Loan ? Department of Computer Science and Engineering, HKUST Slide 3
t t t t[amount]>1200? t[amount]>1200? t[amount]>1200? Summary of Key Concepts (about Tuple Relational Calculus) t loan • t is a tuple variable which can hold a tuple of loan t[salary]: is the value under the salary attribute What is the difference between t[salary] and the salary Loan ? Department of Computer Science and Engineering, HKUST Slide 4
loan branch-name loan-number amount borrower cust-name loan-number Re-Visit the JOIN Operation in Relational Algebra • The “dot” notation tells which table does an attribute come from • The attributes and conditions to be matched in Join are explicitly stated • We could specify “Loan.loan-number > Borrower.loan-number” or even “branch-name > cust-name” for the Join operation (if they make sense!!!) • The attributes in the join results are explicitly specified General notation: Department of Computer Science and Engineering, HKUST Slide 5
loan branch-name loan-number amount borrower cust-name loan-number Natural Join and Equi-Join • Equi-Join: Joins where the match condition between two tuples is “equality” • Natural Join: Loan Borrower • Attributes with the same names in both relations are used for matching the tuples • Conditions are equality • Attributes in both relations, excluding duplicated attributes, are output in the result Department of Computer Science and Engineering, HKUST Slide 6