Sei sulla pagina 1di 3

Database Management Systems I

Laboratory Exercise 6 week 10 Year 1 Semester 2, 2010


Consider the relational schema, which consists of student information (student table), information about courses (course table) and information about student grades (grades table). -- CREATE DATABASE SCHEMA -- student table create table student ( sid char(10) primary key, sname varchar(100), address varchar(200), gpa float, batch char(2)) go -- course table create table course ( cid char(4) primary key, cname varchar(100) unique, credits int) go

-- student's id -- student's name -- student's address -- student's grade point average -- batch which student belongs to

-- course's id -- name of course -- credits for unit

-- grades table create table grades ( sid char(10), -- student's id cid char(4), -- course's id grade char, -- grade earned by student for course primary key(sid, cid), foreign key (sid) references student, foreign key (cid) references course) go

1
SRILANKA INSTITUTE OF INFORMATION TECHNOLOGY

-- LOADING DATABASE SCHEMA -- Loading student table insert into student values ('DIT/05/001', 'Sampath Weerasinghe', '101 Galle Rd., Col-3', 3.2, 'Y1') insert into student values ('DIT/05/011', 'Dulani Wijekoon', '101 Matara Rd., Matara', 2.8, 'Y1') insert into student values ('DIT/05/131', 'Srinivas Sivalingam', '2/3B, Polhengoda Rd., Col-6', 3.1, 'Y2') insert into student values ('DIT/05/021', 'Ajith Makumbura', 'Madpatha Watta, Madapatha', 2.9, 'Y2') insert into student values ('DIT/05/241', 'Mohommed Ismail', '121/4E Polhena Rd., Matara', 3.2, 'Y2') insert into student values ('DIT/06/345', 'Indika Hettige', null, null, null); go -- Loading course table insert into course values ('DBII', 'Database Management Systems II', 4) insert into course values ('SEII', 'Software Engineering II', 4) insert into course values ('IPE', 'Introduction to Programming Environments', 4) insert into course values ('ITP', 'Information Technology Project', 12) go -- Loading grades table insert into grades values ('DIT/05/001', 'DBII', 'B') insert into grades values ('DIT/05/001', 'SEII', 'B') insert into grades values ('DIT/05/001', 'IPE', 'C') insert into grades values ('DIT/05/001', 'ITP', 'A') insert into grades values ('DIT/05/011', 'DBII', 'B') insert into grades values ('DIT/05/011', 'SEII', 'C') insert into grades values ('DIT/05/011', 'ITP', 'B') insert into grades values ('DIT/05/131', 'DBII', 'C') insert into grades values ('DIT/05/131', 'ITP', 'B') insert into grades values ('DIT/05/131', 'IPE', 'A') insert into grades values ('DIT/05/021', 'IPE', 'C') insert into grades values ('DIT/05/241', 'DBII', 'B') insert into grades values ('DIT/05/241', 'SEII', 'A') go 1. Print the number of students in the university. 2. Print the names of students who have obtained an A-grade for Database Management Systems II and having a gpa of above 3.0. 3. For all students who have the character i in their name, print the student name and number of courses that the student has completed. (A student has completed a course if he/she has obtained a grade for the subject in the grades table. A student who has not completed any courses should not consider for printing list)

2
SRILANKA INSTITUTE OF INFORMATION TECHNOLOGY

4. For each student who has completed more than two courses, print the student name and number of courses that he/she has completed.(A student has completed a course if he/she has obtained a grade for the course in the grades table.) 5. Update all C grades obtained by student for Database Management Systems II course to a B grade. 6. Print the total number of credits completed by a student. Print the student name and total number of credits completed in descending order of completed credits. (A student completes the credits for the course if he/she obtains a grade for the course in grades table). 7. Print the number of students in each batch. If a student is not assigned a batch (i.e. batch has NULL value), do not print this as batch. Print the batch and number of students. 8. Print the names of students who have obtained a grade A or B for Database Management System II course. **End of Lab Sheet**

3
SRILANKA INSTITUTE OF INFORMATION TECHNOLOGY

Potrebbero piacerti anche