BAND NAME
MEMBERS
PRICE
MUSIC TYPE
NOTES
HIGH IN DRY
500
ROCK &
ROLL
weddings, balls,
dances preferred
SQUARE
DANCE TRIO
650
COUNTRY &
WESTERN
BLUE SOX
QUARTET
400
JAZZ
YOUNG AND
PROUD
750
ROCK &
ROLL
MATTHEW
AND SON
750
ROCK &
ROLL
1. Create a database file called Bands and a table called NOISEWRKS within the file,
to contain the information above.
List all the Rock & Roll bands that cost less than $700. Save the Query.
8. List all the band names and the price for bands which play Country & Western. Save
the Query.
9. List all the bands which play either Rock & Roll or jazz. Save the Query.
10. How many bands cost more than $650? Save the query
11. What is the average number of members in the jazz bands? Save the Query.
12. Create and print a report for your file. Include in your report the band name, the
price and the notes kept on each band, grouped by music type. Add your name, the
assignment number, question number and date to the bottom right corner of the
report. Format the report professionally on the page.
13. Print the report above for only those bands which have five members.
14. Also create the given two tables and populate with the appropriate data.
1) Music Director (Director Name: string, Band Name: String, Number of Albums:
Integer, Number of Hit Songs: Integer) and
2) Album (album identifier: integer, director name: string, number of songs: integer,
album name: string)
15. Specify the relationships also specify the primary and foreign keys for all the tables
mentioned above.
II.
III.
IV.
V.
VI.
VII.
1. Create the above relations including all primary and foreign key integrity
constraint , with SQL.
2. Add Tuples to all relations using INSERT statement.
3. Add constraint that if city name is not provided in the Branch relation it takes
4.
5.
6.
7.
8.
9. Alter Relation Viewing add constraint that attribute Comment will take default
value NIL.
10. Write SQL Statement to delete all the tuples of relation Registration but table will
not be deleted from the database.
Minit
LName
SSN
BDate
Address
Sex
Salary
SuperSSN
DepNo
Department
DName DepNo MgrSSN
MgrSDate
Dept_Locations
DepNo
DLocation
Project
PName
PNumber
PLocation
DepNo
Works_On
ESSN
PNo
Hours
Dependent
ESSN
Dependent_Name
Sex
BDate
Relationship
1. Refer to the schema given above create all tables with primary, foreign key, not null,
default and check constraints and populate all the tables (atleast 5 rows in each table).
2. Update the relation Works_On change the datatype of hours attribute from char to
integer.
3. List the name of employees whose salary is between 30000 and 50000.
4. List the name of all employees who work in department 5.
List the name of staff who work in the branch whose street address is 163 Main
street.
For each branch list the branch number,staff number and staff name who manage
properties including the city in which the branch is located and the properties that
Find the number of different staff whose DOB is 01-Feb-1991 and whose name
starts with A.
For each branch office with more than one member of staff find the total number of
staff working in a branch with average of their salaries.
Display the name of Professors who work in the department that have fewer than 50
PhD students.
Display the name of students with lowest CGPA.
For each Database Course print the course number, section number and average
enrolled in them.
Display the name of department that have one or more majors who are under 18
year old.
Retrieve the name of students who are taking both Computer Science Course and
Mathematics Course.
For those department that have no major taking a Computer Graphics Course
(LAB TEST 1)
Lab and Date: Week 9: 24 Sep 30 Sep
Syllabus: SQL
the movie that has the maximum TotalSalaryCost (total salary paid to stars).
total gross sales of all movies that won some Oscar award in the 1960s.
for each director, the total number of his/her movies that have won an Oscar.
for each star, the total number of movies for which he/she has won a Best
Actor/Actress Oscar AND that have won at least two Oscars.
the list of all directors who received the "Best Director" award, even though the
movie for which they received the award had an average rating of less than 5.
Write an UPDATE statement that changes the filmType of a movie that has won
an Oscar to 'OscarWinner'.
II
(i) Using SQL Scenario above, which of the following SQL queries gives a list of
departments and their employees?
a. SELECT depname,empname
FROM departments, employees
WHERE departments.depno = employees.empno
;
b. SELECT depname,empname
FROM departments, employees, workfor
WHERE departments.depno = workfor.depno
AND workfor.empno = employees.empno
;
c. SELECT depname,empname
FROM departments, workfor
WHERE departments.depno = workfor.depno
;
d. SELECT depno,empno
FROM workfor
;
e. None of the above.
(ii) which of the following SQL queries gives the number of employees in each
department?
a. SELECT depname,COUNT(depno) FROM
departments, employees, workfor WHERE
departments.depno = workfor.depno AND
workfor.empno = employees.empno
;
b. SELECT empno,COUNT(*)
FROM departments, workfor
WHERE departments.depno = workfor.depno
GROUP BY depno
;
c. SELECT depname,COUNT(empno)
FROM departments, workfor
WHERE departments.depno =
workfor.depno
GROUP BY depname
;
d. SELECT depname,COUNT(empno) FROM
departments, employees, workfor WHERE
departments.depno = workfor.depno AND
workfor.empno = employees.depno GROUP BY
depno
e. None of the above.
(a) The university keeps track of each student's name (SNAME), student number (SNUM), social
security number (SSSN), current address (SCADDR) and phone (SCPHONE), permanent
address (SPADDR) and phone (SPPHONE), birthdate (BDATE), sex (SEX), class (CLASS)
(freshman, sophomore, ..., graduate), major department (MAJORDEPTCODE), minor
department (MINORDEPTCODE) (if any), and degree program (PROG) (B.A., B.S., ..., Ph.D.).
Both SSSN and student number have unique values for each student.
(b) Each department is described by a name (DEPTNAME), department code (DEPTCODE),
office number (DEPTOFFICE), office phone (DEPTPHONE), and college (DEPTCOLLEGE).
Both name and code have unique values for each department.
(c) Each course has a course name (CNAME), description (CDESC), code number (CNUM),
number of semester hours (CREDIT), level (LEVEL), and offering department (CDEPT). The
value of code number is unique for each course.
(d) Each section has an instructor (INSTUCTORNAME), semester (SEMESTER), year (YEAR),
course (SECCOURSE), and section number (SECNUM). Section numbers distinguish different
sections of the same course that are taught during the same semester/year; its values are 1, 2,
3, ...; up to the number of sections taught during each semester.
(e) A transcript refers to a student (SSSN), refers to a particular section, and grade (GRADE).
Design a relational database schema for this database application. First show all the
functional dependencies that should hold among the attributes. Then, design relation
schemas for the database. Create Normalized (upto III NF) relations in SQL and add
primary and foreign key constraints and answer the following queries:
Display the name of students whose grade is A+ for the Database course.
Display the course name run at the same time for two different departments.
For each department display the Instructor name taking maximum number of
classes.
Retrieve the grade list of all students for each department.
For different courses display the name of course for which the credit and level of
one course is greater than the credit and level of another course.
Assignment 10 (Practice Assignment)
Lab and Date: Week 12 & 13: 23 Oct 01 Nov
Project Phase II Evaluation and PL/SQL
Practice the given code and rectify the error, if any:
Q.1 Consider the given table T1 and execute the PL/SQL codes given below and check
for the output, identify the error if any;
(a)
DECLARE
a NUMBER;
b NUMBER;
BEGIN
SELECT e, f INTO a, b FROM T1 WHERE e>1;
IF b=1 THEN INSERT INTO T1 VALUES ( b, a );
ELSE INSERT INTO T1 VALUES ( b+10, a+10 );
END IF;
END;
(b)
DECLARE
a NUMBER;
b NUMBER;
BEGIN
SELECT e, f INTO a, b FROM T1 WHERE e>1;
IF b=1 THEN INSERT INTO T1 VALUES ( b, a );
ELSE INSERT INTO T1 VALUES ( b+10, a+10 );
END IF;
END;
(c)
DECLARE
i NUMBER := 1;
BEGIN
LOOP
INSERT INTO T1 VALUES ( i, i );
i := i+1;
EXIT WHEN i>100;
END LOOP;
END;
(d)
DECLARE
a T1.e%TYPE;
b T1.f%TYPE;
CURSOR T1Cursor IS
todays_date date;
begin
todays_date :=sysdate;
dbms_output.put_line('Todays date is:');
dbms_output.put_line(todays_date);
end;
(f) declare
todays_date date;
current_day varchar2(9);
begin
todays_date :=sysdate;
--extract day portion from current date and trim
--trailing blank spaces
current_day :=to_char(todays_date,'day');
current_day :=initcap(current_day);
current_day :=rtrim(current_day);
if current_day = 'Friday' then
dbms_output.put_line('Today is Friday');
elsif current_day = 'sunday' then
dbms_output.put_line('Today is Sunday');
elsif current_day ='Tuesday' then
dbms_output.put_line('Today is Tuesday ');
else
dbms_output.put_line('current day not found');
end if;
end;
(g) declare
n number:=10;
fact number:=1;
temp number;
begin
temp:=n;
while n>0
loop
fact:=fact*n;
n:=n-1;
end loop;
dbms_output.put_line('Factorial of'||temp||'is'||fact);
end;
Q.2 Write PL/SQL Procedure for the generation of Fibonacci series.
Q.3 Write a PL/SQL Program using cursor to display the second highest
salary of an employee. Relation Employee is EMP (eid, ename, salary, dept)
(LAB TEST II)
Lab and Date: Week 14: 11 Nov 16 Nov
Syllabus: PL/SQL
check the status of the insert transaction. Also an exception is raised if any data type mismatch
occurs at the time of insertion.
Q.3 Write a Trigger to automatically add Eid and display the department of employee in
department table once an employee record is inserted into the employee table.
Q.4 Declare a cursor to list the department name (dname), total number of employees (ttemp),
total salary (ttsal), and average salary (avsal) for each department from the department table and
employee table order by the department name. In the exception section, add the no data found
exception and display the error message.. Add the Others exception to detect other problems.