Mathematically speaking:
A set of attribute SK is a
superkey
if and only if:
|
I.e., a key is a minimal superkey....
You must use the primary key throughout the database (or else, you database career life will be very difficult)
Example: Grade report
|
Pictorailly:
![]() |
|
|
|
|
|
![]() |
Example:
![]() |
|
|
|
Works_on * Employee
![]() |
Sample data:
Works_on: (source relation) ESSN PNO HOURS --------- ---------- ---------- 123456789 1 32.5 123456789 2 7.5 333445555 10 10 333445555 3 10 333445555 2 10 333445555 20 10 453453453 2 20 453453453 1 20 666884444 3 40 888665555 20 1 987654321 30 20 987654321 20 15 987987987 10 35 987987987 30 5 999887777 30 30 999887777 10 10 |
Employee: SSN FNAME LNAME --------- ---------- ---------- 123456789 John Smith 333445555 Frank Wong 453453453 Joyce English 666884444 John Doe 888665555 James Borg 987654321 Jack Wallace 987987987 Jake Jones 999887777 Alice Miller |
Worsk_on * Employee:
Works_on * Employee: ESSN PNO HOURS SSN FNAME LNAME --------- ---------- ---------- --------- ---------- ---------- 123456789 1 32.5 123456789 John Smith 123456789 2 7.5 123456789 John Smith 333445555 10 10 333445555 Frank Wong 333445555 3 10 333445555 Frank Wong 333445555 2 10 333445555 Frank Wong 333445555 20 10 333445555 Frank Wong 453453453 2 20 453453453 Joyce English 453453453 1 20 453453453 Joyce English 666884444 3 40 666884444 John Doe 888665555 20 1 888665555 James Borg 987654321 30 20 987654321 Jack Wallace 987654321 20 15 987654321 Jack Wallace 987987987 10 35 987987987 Jake Jones 987987987 30 5 987987987 Jake Jones 999887777 30 30 999887777 Alice Miller 999887777 10 10 999887777 Alice Miller |
The key will identify one unique tuple in the second relation.
|
|
![]() |
Works_on * Project * Department * Employee
Example database content:
Works_on ESSN PNO HOURS --------- ---------- ---------- 123456789 1 32.5 123456789 2 7.5 333445555 2 10 333445555 3 10 333445555 10 10 333445555 20 10 999887777 30 30 999887777 10 10 987654321 30 20 987654321 20 15 666884444 3 40 453453453 1 20 453453453 2 20 987987987 30 5 987987987 10 35 888665555 20 1 |
Project PNUMBER PNAME DNUM ---------- --------------- ---------- 1 ProductX 5 2 ProductY 5 3 ProductZ 5 10 Computerization 4 20 Reorganization 1 30 Newbenefits 4 |
Department DNUMBER DNAME MGRSSN ---------- --------------- --------- 5 Research 333445555 4 Administration 987654321 1 Headquarters 888665555 |
Employee: SSN FNAME LNAME --------- ---------- ---------- 123456789 John Smith 333445555 Frank Wong 453453453 Joyce English 666884444 John Doe 888665555 James Borg 987654321 Jack Wallace 987987987 Jake Jones 999887777 Alice Miller |
ESSN PNO HOURS PNUM PNAME DNUM DNUM DNAME MGRSSN SSN FNAME LNAME --------- --- ----- ---- -------- ---- ---- ------------ --------- --------- ----- ----- 123456789 1 32.5 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 123456789 2 7.5 2 Product 5 5 Research 333445555 333445555 Frank Wong 333445555 2 10 2 ProductY 5 5 Research 333445555 333445555 Frank Wong 333445555 3 10 3 ProductZ 5 5 Research 333445555 333445555 Frank Wong 333445555 10 10 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 333445555 20 10 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg 999887777 30 30 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 999887777 10 10 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 987654321 30 20 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 987654321 20 15 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg 666884444 3 40 3 ProductZ 5 5 Research 333445555 333445555 Frank Wong 453453453 1 20 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 453453453 2 20 2 ProductY 5 5 Research 333445555 333445555 Frank Wong 987987987 30 5 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 987987987 10 35 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 888665555 20 1 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg |
|
|
|
ESSN PNO HOURS PNUM PNAME DNUM DNUM DNAME MGRSSN SSN FNAME LNAME --------- --- ----- ---- -------- ---- ---- ------------ --------- --------- ----- ----- 123456789 1 32.5 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 123456789 2 7.5 2 Product 5 5 Research 333445555 333445555 Frank Wong 333445555 2 10 2 ProductY 5 5 Research 333445555 333445555 Frank Wong 333445555 3 10 3 ProductZ 5 5 Research 333445555 333445555 Frank Wong 333445555 10 10 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 333445555 20 10 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg 999887777 30 30 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 999887777 10 10 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 987654321 30 20 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 987654321 20 15 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg 666884444 3 40 3 ProductZ 5 5 Research 333445555 333445555 Frank Wong 453453453 1 20 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 453453453 2 20 2 ProductY 5 5 Research 333445555 333445555 Frank Wong 987987987 30 5 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 987987987 10 35 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 888665555 20 1 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg |
Imagine you need to pick 3 tuples randomly from the above result.
And just suppose you happen to pick the first 3:
ESSN PNO HOURS PNUM PNAME DNUM DNUM DNAME MGRSSN SSN FNAME LNAME --------- --- ----- ---- -------- ---- ---- ------------ --------- --------- ----- ----- 123456789 1 32.5 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 123456789 2 7.5 2 Product 5 5 Research 333445555 333445555 Frank Wong 333445555 2 10 2 ProductY 5 5 Research 333445555 333445555 Frank Wong |
You would get the same result if you pick the first 3 tuples in the source relation and then perform the join:
Works_on ESSN PNO HOURS --------- ---------- ---------- 123456789 1 32.5 123456789 2 7.5 333445555 2 10 |
Project PNUMBER PNAME DNUM ---------- --------------- ---------- 1 ProductX 5 2 ProductY 5 3 ProductZ 5 10 Computerization 4 20 Reorganization 1 30 Newbenefits 4 |
Department DNUMBER DNAME MGRSSN ---------- --------------- --------- 5 Research 333445555 4 Administration 987654321 1 Headquarters 888665555 |
Employee: SSN FNAME LNAME --------- ---------- ---------- 123456789 John Smith 333445555 Frank Wong 453453453 Joyce English 666884444 John Doe 888665555 James Borg 987654321 Jack Wallace 987987987 Jake Jones 999887777 Alice Miller |
|
The Maximum foreign key join Works_on * Project * Department * Employee:
ESSN PNO HOURS PNUM PNAME DNUM DNUM DNAME MGRSSN SSN FNAME LNAME --------- --- ----- ---- -------- ---- ---- ------------ --------- --------- ----- ----- 123456789 1 32.5 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 123456789 2 7.5 2 Product 5 5 Research 333445555 333445555 Frank Wong 333445555 2 10 2 ProductY 5 5 Research 333445555 333445555 Frank Wong 333445555 3 10 3 ProductZ 5 5 Research 333445555 333445555 Frank Wong 333445555 10 10 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 333445555 20 10 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg 999887777 30 30 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 999887777 10 10 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 987654321 30 20 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 987654321 20 15 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg 666884444 3 40 3 ProductZ 5 5 Research 333445555 333445555 Frank Wong 453453453 1 20 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 453453453 2 20 2 ProductY 5 5 Research 333445555 333445555 Frank Wong 987987987 30 5 30 Newbenef. 4 4 Administr. 987654321 987654321 Jack Wall. 987987987 10 35 10 Computer. 4 4 Administr. 987654321 987654321 Jack Wall. 888665555 20 1 20 Reorgani. 1 1 Headquart. 888665555 888665555 James Borg |
The Join Synopsis of the Maximum foreign key join Works_on * Project * Department * Employee:
ESSN PNO HOURS PNUM PNAME DNUM DNUM DNAME MGRSSN SSN FNAME LNAME --------- --- ----- ---- -------- ---- ---- ------------ --------- --------- ----- ----- 123456789 1 32.5 1 ProductX 5 5 Research 333445555 333445555 Frank Wong 123456789 2 7.5 2 Product 5 5 Research 333445555 333445555 Frank Wong 333445555 2 10 2 ProductY 5 5 Research 333445555 333445555 Frank Wong |
ESSN PNO HOURS PNUM PNAME DNUM DNUM DNAME MGRSSN --------- --- ----- ---- -------- ---- ---- ------------ --------- 123456789 1 32.5 1 ProductX 5 5 Research 333445555 123456789 2 7.5 2 Product 5 5 Research 333445555 333445555 2 10 2 ProductY 5 5 Research 333445555 |
ESSN PNO HOURS PNUM PNAME DNUM --------- --- ----- ---- -------- ---- 123456789 1 32.5 1 ProductX 5 123456789 2 7.5 2 Product 5 333445555 2 10 2 ProductY 5 |
![]() |
In this case, we can extract the following join synopses from the maximum foreign key join synopses:
|
![]() |
In this case, we can extract the following join synopses from the maximum foreign key join synopses:
|
|
Execute the following algorithm when a tuple t is inserted in relation R
Notations: R = source relation SR = ramdom sample of R J(SR) = join synopsis of relation R R * R2 * R3 * .... * Rk is the maximum foreign key join |
Execute the following algorithm when a tuple t is deleted from relation R
Notations: R = source relation SR = ramdom sample of R J(SR) = join synopsis of relation R R * R2 * R3 * .... * Rk is the maximum foreign key join |
|
![]() |
![]() |