Docsity

Oracle SQLPlus: Tables, Data Insertion, and Queries for CS348 Fall-2008, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
CS348 Fall-2008: Project 1 Solution: Oracle SQLPlus (130 Points)
——————-Questions 1 and 2——————–
create table Student(
Student id char(20),
FName char(20),
LName char(20),
DOB date,
primary key(Student id));
create table Department(
Dept id char(20),
Dept name char(50),
primary key(Dept id));
create table Course(
Course num char(20),
Dept id char(20) not null,
Course name char(50) not null,
Num credits integer not null,
primary key(Course num),
foreign key(Dept id) references Department(Dept id);
create table Enrollment(
Student id char(20),
Course num char(50),
Semester char(20),
Letter grade char not null,
primary key(Student id,Course num,Semester),
check(Letter grade in (’A’,’B’,’C’,’D’,’F’)),
check (Semester in (’Fall’,’Spring’,’Summer’)));
——————-Questions 3——————–
describe Student;
describe Department;
describe Course;
describe Enrollment;
——————-Questions 4——————–
insert into Student values(’11-111’,’Hong’,’Bach’,’12-Jan-1984’);
insert into Student values(’22-222’,’Glen’,’Bateman’,’05-Jan-1985’);
insert into Student values(’33-333’,’Royce’,’Biddick’,’16-Mar-1984’);
1
pf3
pf4
pf5

Partial preview of the text

Download Oracle SQLPlus: Tables, Data Insertion, and Queries for CS348 Fall-2008 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CS348 Fall-2008: Project 1 Solution: Oracle SQLPlus (130 Points)

——————-Questions 1 and 2——————–

create table Student( Student id char(20), F Name char(20), L Name char(20), DOB date, primary key(Student id));

create table Department( Dept id char(20), Dept name char(50), primary key(Dept id));

create table Course( Course num char(20), Dept id char(20) not null, Course name char(50) not null, Num credits integer not null, primary key(Course num), foreign key(Dept id) references Department(Dept id);

create table Enrollment( Student id char(20), Course num char(50), Semester char(20), Letter grade char not null, primary key(Student id,Course num,Semester), check(Letter grade in (’A’,’B’,’C’,’D’,’F’)), check (Semester in (’Fall’,’Spring’,’Summer’)));

——————-Questions 3——————–

describe Student; describe Department; describe Course; describe Enrollment;

——————-Questions 4——————–

insert into Student values(’11-111’,’Hong’,’Bach’,’12-Jan-1984’); insert into Student values(’22-222’,’Glen’,’Bateman’,’05-Jan-1985’); insert into Student values(’33-333’,’Royce’,’Biddick’,’16-Mar-1984’);

insert into Student values(’44-444’,’William’,’Nabak’,’01-Jun-1984’); insert into Student values(’55-555’,’Linda’,’Nygaard’,’23-Jun-1984’); insert into Student values(’66-666’,’Deepak’,’Gandhi’,’11-Dec-1984’); insert into Student values(’77-777’,’Bruce’,’Tackes’,’16-Jan-1985’); insert into Student values(’88-888’,’Paul’,’Thomson’,’04-Apr-1984’); insert into Student values(’99-999’,’Alice’,’Keen’,’06-Oct-1984’);

insert into Department values(’CS’,’Computer Science’); insert into Department values(’ECE’,’Electrical and Computer Engineering’); insert into Department values(’MA’,’Department of Mathematics’); insert into Department values(’PHYS’,’Department of Physics’); insert into Department values(’CHM’,’Department of Chemistry’);

insert into Course values(’CS 42600’,’CS’,’Computer Security’,1); insert into Course values(’CS 30700’,’CS’,’Software Engineering’,2); insert into Course values(’CS 24000’,’CS’,’Programming in C’,3); insert into Course values(’ECE 202’,’ECE’,’Linear Circuit’,3); insert into Course values(’ECE 301’,’ECE’,’Signals and Systems’,3); insert into Course values(’CHM 25501’,’CHM’,’Organic Chemistry’,2); insert into Course values(’ECE 368’,’ECE’,’Data Structure’,1);

insert into Enrollment values(’66-666’,’CS 42600’,’Fall’,’A’); insert into Enrollment values(’66-666’,’CS 24000’,’Fall’,’F’); insert into Enrollment values(’22-222’,’CS 24000’,’Fall’,’B’); insert into Enrollment values(’77-777’,’CS 42600’,’Spring’,’B’); insert into Enrollment values(’99-999’,’CHM 25501’,’Spring’,’D’); insert into Enrollment values(’22-222’,’ECE 202’,’Summer’,’C’); insert into Enrollment values(’22-222’,’CHM 25501’,’Fall’,’A’); insert into Enrollment values(’33-333’,’ECE 368’,’Fall’,’B’); insert into Enrollment values(’77-777’,’CHM 25501’,’Summer’,’C’); insert into Enrollment values(’22-222’,’ECE 301’,’Summer’,’F’); insert into Enrollment values(’33-333’,’CS 24000’,’Spring’,’C’); insert into Enrollment values(’44-444’,’ECE 368’,’Spring’,’A’); insert into Enrollment values(’44-444’,’CS 24000’,’Spring’,’F’); insert into Enrollment values(’77-777’,’CS 30700’,’Fall’,’B’); insert into Enrollment values(’99-999’,’ECE 301’,’Fall’,’F’); insert into Enrollment values(’99-999’,’CS 24000’,’Spring’,’B’); insert into Enrollment values(’88-888’,’ECE 301’,’Spring’,’C’); insert into Enrollment values(’88-888’,’CS 24000’,’Spring’,’A’); insert into Enrollment values(’33-333’,’ECE 301’,’Spring’,’A’);

——————-Questions 5——————–

select * from Student; select * from Course;

from Enrollment where Semester=’Fall’ group by Student id) Id where Student.Student id=Id.Student id;

–(g)– SELECT Course num, COUNT() student count FROM Enrollment WHERE Semester = ’Spring’ GROUP BY Course num HAVING COUNT() > 3 ORDER BY student count ASC;

–(h)– SELECT F Name, L Name, COUNT() Enrollment count FROM Student, Enrollment WHERE Student.student id = Enrollment.student id GROUP BY Student id HAVING COUNT() >= (select count(*) from Enrollment group by Student id);

——————-Questions 7——————–

CREATE VIEW TotalCredits AS (SELECT F Name, L Name, COUNT(*) Total courses, SUM(Num credits) Total credits FROM Student, Enrollment, Course WHERE Student.Student id = Enrollment.Student id And Enrollment.Course num = Course.Course num GROUP BY F Name, L Name);

——————-Questions 8——————–

SELECT F Name, L Name FROM TotalCredits WHERE Total credits < 4;

——————-Questions 9——————–

DELETE FROM Enrollment; DELETE FROM Course; DELETE FROM Department; DELETE FROM Student;

——————-Questions 10——————–

DROP VIEW TotalCredits;

——————-Questions 11——————–

DROP TABLE Enrollment; DROP TABLE Course; DROP TABLE Department;

DROP TABLE Student;

——————-Questions 12——————–

–(a)– –Views are just queries over the base tables. Therefore, any change in the data in the base tables will affect querying the views. –In our case, the query in question 8 is empty, so if we run the query again after step 9, the results will be the same. –But, in general, the results are not the same.

–(b)– –The inconsistency is in relation Enrollment. The student 33-333 is registered in course PHY303 that does not exist in relation Course. –To prevent this inconsistency, we can add the following constraint to table Enrollment : –foreign key(Course num) references Course(Course num);