View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
“ For a given student and course, there is a single grade.” vs. “Students can take only one course, and receive a single grade for that course; further, no two students in a course receive the same grade.”
Used carelessly, an IC can prevent the storage of database instances that arise in practice!
3 relations: Employees, Hourly_Emps and Contract_Emps.
Hourly_Emps : Every employee is recorded in Employees. For hourly emps, extra info recorded in Hourly_Emps ( hourly_wages , hours_worked , ssn ) ; must delete Hourly_Emps tuple if referenced Employees tuple is deleted).
Queries involving all employees easy, those involving just Hourly_Emps require a join to get some attributes.
What are the additional constraints in the 2nd diagram?
Slide No:L4-5 age pname Dependents Covers age pname Dependents Purchaser Bad design Better design name Employees ssn lot Policies policyid cost Beneficiary policyid cost Policies name Employees ssn lot
create view all_customer as ( select branch_name, customer_name from depositor, account where depositor.account_number = account.account_number ) union ( select branch_name, customer_name from borrower, loan where borrower.loan_number = loan.loan_number ) select customer_name from all_customer where branch_name = 'Perryridge'
Find all branches where the total account deposit is greater than the average of the total account deposits at all branches.
Slide No:L5-9 with branch_total ( branch _ name , value ) as select branch _ name , sum ( balance ) from account group by branch _ name with branch _ total _ avg ( value ) as select avg ( value ) from branch _ total select branch _ name from branch _ total , branch _ total_avg where branch_total.value >= branch_total_avg.value
Note: the exact syntax supported by your database may vary slightly.
E.g. Oracle syntax is of the form with branch_total as ( select .. ), branch_total_avg as ( select .. ) select …