You are on page 1of 4

Part 1:

1. Create a catalog which contain all possible combinations of teams and tournaments
(1 point)
Select TOURNEY.TourneyID, TeamID, TeamName
From TEAMS inner join TOURNEY_MATCHES ON (TEAMS.TeamID =
TOURNEY_MATCHES.OddLaneTeamID and TEAMS.TeamID =
TourneyID.EvenLaneTeamID)
Inner join TOURNEY ON TOURNEY_MATCHES.TourneyID = TOURNEY.TourneyID
Group by TOURNEY.TourneyID, TeamID, TeamName
2. Show all information of bowlers who never has any raw score (1 point)
Select B.* from BOWLERS B inner join BOWLER_SCORES B1 ON B.BowlerID =
B1.BowlerID
Where B1.Rawscore =0
Group by
B.BowlerID,B.BowlerFirstName,B.BowlerLastName,B.TeamID,B.BowlerPhoneNu
mber,
B.BowlerZipcode, B.BowlerState,B.City,
B.BowlerStreetAddress,B.BowlerMiddleInit

3. Show all information of teams that has at least one bowler having handicap score
greater than
150 and teams that do not have any bowlers having handicap score greater
than 150 (1 point)
Select TEAMS.* From TEAMS inner join BOWLERS ON TEAMS.BowlerID =
BOWLERS.BowlerID
Inner join BOWLERS_SCORES inner join BOWLERS.BowlerID =
BOWLERS_SCORES.BowlerID
Where HandicapScore >= 150 Group by TeamID,TeamName,CaptainID
4. Show all information of bowlers who belong to a team or do not belong to any team.
If the bowler belongs to a team, only show bowlers who belong to a team has
average raw score greater than 150. If the bowler does not belong to any team,
show his/her information (1 point)

Select Bowlers.* From (select B.* from BOWLERS B inner join TEAMS ON
TEAMS.TeamID = B.TeamID Inner join BOWLERS_SCORES ON
BOWLERS.BowlerID = BOWLERS_SCORES.BowlerID
Group by
B.BowlerID,B.BowlerFirstName,B.BowlerLastName,B.TeamID,B.BowlerPhoneNu
mber,
B.BowlerZipcode, B.BowlerState,B.City,
B.BowlerStreetAddress,B.BowlerMiddleInit. Having avg(RawScore)>150 ) as
Bowlers, (select B.* from BOWLERS B inner join TEAMS ON TEAMS.TeamID =
B.TeamID Inner join BOWLERS_SCORES ON BOWLERS.BowlerID <>
BOWLERS_SCORES.BowlerID Group by
B.BowlerID,B.BowlerFirstName,B.BowlerLastName,B.TeamID,B.BowlerPhoneNu
mber,
B.BowlerZipcode, B.BowlerState,B.City,
B.BowlerStreetAddress,B.BowlerMiddleInit
) as Bowlers1
5. Show both team info that does not have any bowlers and bowler info who do not
belong to any team (1 point)
Select TEAMS.* from TEAMS inner join BOWLERS ON TEAMS.TeamID
<>BOWLERS.TeamID

Part 2:
6. Create database schema with name Employee Information (1 point).
7. Create 3 tables based on the logical schema below to fulfill the following
requirements
a. Correctly define primary keys and foreign keys (1 point)
b. No attributes can store empty values (1 point)
c. CourseTitle only can store Business Analytics, Marketing, and MIS as its value (1
point)
d. Import 4 sample records for all tables (1 point)

Supervise

Employee
PK

Course

EmployeeID
PK

EmployeeFirstName
EmployeeLastName

CourseID

CourseTitle

EmployeeCourse
PK

EmployeeCourseID
DateCompleted

Logical Schema:
Create table Employee(
EmployeeID int,
EmployeeFirstName varchar(),
EmployeeLastName,
SupervisorID
)
Course(CourseID, CourseTitle)
EmployeeCourse(EmployeeCourseID, EmployeeID, CourseID, DateCompleted)
Legend:
Primary Key: Bold and underline.
Foreign Key: Italic

Create table Employee(


EmployeeID int,
EmployeeFirstName varchar(50),
EmployeeLastName varchar(50),
SupervisorID int,
PRIMARY KEY (EmployeeID)
);
insert into Employee values(1,'','',4444);
insert into Employee values(2,'','',1111);

insert into Employee values(3,'','',5555);


insert into Employee values(4,'','',7845);

create table Course(


CourseID int,
CourseTitle varchar(50)
CONSTRAINT chk_Title CHECK (CourseTitle IN ('Business Analytics',
'Marketing', 'MIS' )),
PRIMARY KEY (CourseID)
);
insert
insert
insert
insert

into
into
into
into

Course
Course
Course
Course

values(1,'MIS');
values(2,'Business Analytics');
values(3,'Marketing');
values(4,'MIS');

EmployeeCourse(
EmployeeCourseID int,
EmployeeID int FOREIGN KEY REFERENCES Persons(EmployeeID),
CourseID int FOREIGN KEY REFERENCES Persons(CourseID),
DateCompleted date,
PRIMARY KEY (EmployeeCourseID)
);

insert
insert
insert
insert

into
into
into
into

EmployeeCourse
EmployeeCourse
EmployeeCourse
EmployeeCourse

values(1,2,2,'03-04-2016');
values(2,3,3,'03-04-2016');
values(3,2,4,'03-04-2016');
values(4,1,1,'03-04-2016');

You might also like