CSc 4710/6710, Database Systems
Spring 2008
Homework 5 (Due: 21 March, 2008 - Friday)

Consider the following relational database:
drop table teams cascade constraints;
create table teams (
  tname varchar2(20),
  primary key (tname)
);
insert into teams values ('Braves');
insert into teams values ('Cardinals');
insert into teams values ('Cubs');
insert into teams values ('Diamondbacks');
insert into teams values ('Indians');
--
drop table results cascade constraints;
create table results (
  when date, -- includes time of game as well
  home varchar2(20),
  visitor varchar2(20),
  hruns number(3),
  vruns number(3),
  primary key (when,home),
  foreign key (home) references teams,
  foreign key (visitor) references teams
);
--
insert into results values ('20-MAR-2004','Diamondbacks','Cubs',10,11);
--
insert into results values ('23-MAR-2004','Braves','Cardinals',0,1);
insert into results values ('27-MAR-2004','Cardinals','Cubs',7,9);
insert into results values ('27-MAR-2004','Indians','Braves',1,0);
--
insert into results values ('30-MAR-2004','Braves','Cubs',10,5);
insert into results values ('01-APR-2004','Indians','Diamondbacks',8,8);
--
insert into results values ('15-APR-2004','Diamondbacks','Braves',3,11);
insert into results values ('17-APR-2004','Indians','Cardinals',7,11);
--
insert into results values ('20-APR-2004','Cardinals','Diamondbacks',10,12);
insert into results values ('22-APR-2004','Cubs','Indians',7,4);
--insert into results values ('24-APR-2004','Cubs','Diamondbacks',7,12);
--
insert into results values ('29-APR-2004','Cardinals','Braves',2,10);
--
insert into results values ('01-MAY-2004','Braves','Indians',14,14);
insert into results values ('01-MAY-2004','Cubs','Cardinals',10,0);
--
--insert into results values ('04-MAY-2004','Cubs','Braves',10,8);
insert into results values ('04-MAY-2004','Diamondbacks','Indians',8,7);
--
insert into results values ('08-MAY-2004','Braves','Diamondbacks',6,8);
--
insert into results values ('13-MAY-2004','Cardinals','Indians',3,6);
--
insert into results values ('15-MAY-2004','Diamondbacks','Cardinals',7,13);
insert into results values ('15-MAY-2004','Indians','Cubs',6,8);
--
insert into results values ('18-MAY-2004','Diamondbacks','Cubs',13,5);
--
insert into results values ('22-MAY-2004','Braves','Cardinals',3,6);
--
Write view definition(s) to create "standings" information from the database. A sample query on the view is shown below:
SQL> select * from standings;

TEAM                       WINS     LOSSES       TIES PERCEN
-------------------- ---------- ---------- ---------- ------
Cubs                          5          2          0   .714
Diamondbacks                  4          3          1   .563
Cardinals                     4          5          0   .444
Braves                        3          4          1   .438
Indians                       2          4          2   .375

Page Maintained by raj@cs.gsu.edu