NTU
2011-06-05 13:14:06 UTC
TABLE - http://i53.tinypic.com/zn8yns.jpg
You are required to write the appropriate CREATE TABLE and ALTER TABLE statements to implement the tables above.
You must ensure the following:
i. All data types are accurately defined;
ii. All primary key and foreign key constraints are accurately defined and labelled.
Answer to question A -
I am pretty sure this is the correct answer:
CREATE TABLE Branch
(
BranchNo smallint,
Address char(50),
TelNo char(20),
PRIMARY KEY (BranchNo),
Mgr_StaffNo smallint FOREIGN KEY REFERENCES Staff(StaffNo)
)
CREATE TABLE Staff
(
StaffNo smallint,
StaffName char(50),
Salary decimal(7,2),
PRIMARY KEY (StaffNo),
BranchNo smallint FOREIGN KEY REFERENCES Branch(BranchNo)
)
Question B-
TABLE - http://i53.tinypic.com/zn8yns.jpg
Assume the tables you’ve implemented in a) have been populated with some realistic data. You are now required to do the following:
Write an SQL query to list the branch number, staff name and salary for those members of staff who earn higher than the average salary for their branch; sort by branch number.
IM stuck on question b, please Help (best answer will get 10 points :D)
Thanks in advance