You are on page 1of 20

Assignment – 1

Lab Exercises

DDL COMMANDS CREATING A TABLE LAB-01


(1) Student Information Table: student Schedule_Id varchar2(20)
Student_id varchar2(20) Day number(1)
Last_name varchar2(25) Starting_Time date
First_name varchar2(20) Duration number
Dob varchar2(20) (7) Class Location Information: class_loc
Address varchar2(50) Class_Building varchar2(25)
City varchar2(20) Class_Room varchar2(25)
State varchar2(20) Seating_Capacity varchar2(2)
ZipCode number(6) (8) Class Table: class_table
Telephone number(8) Class_Id varchar2(20) primarykey
Mobile number(10) Schedule_Id varchar2(20)
Email varchar2(100) Class_Building varchar2(25)
(2) Department Information Table: deptt Class_Room varchar2(25)
dept_id varchar2(3) primarykey Course_Id varchar2(5)
dept_name varchar2(25) Department_Id varchar2(20) foreign key
(3) Faculty's Information Table: faculty Dept_info(Department_id)
Faculty_id varchar2(20) primarykey Faculty_Id varchar2(20) Faculty(Faculty_id)
dept_id varchar2(3) Foreignkey Semester varchar2(6)
designation varchar2(20) School_Year date
d_o_j date (9) Student Grade Information Table: grade_info
Last_Name varchar2(25) Student_Id varchar2(20)
First_Name varchar2(200) Class_Id varchar2(20)
Telephone number(8) Grade varchar2(2)Check
mobile number(10) Grade in ('A','A+','A-','B','B+','B-',
Email varchar2(30) 'C','C+',C-','D','D+','D-','F','F+','F-')
Date_Grade_Assigned date
(4) Course Information Table: courses
Course_Id varchar2(10) (10) Describe the structure of the following tables.
dept_Id varchar2(3) foreignkey 1. Student information table
Title varchar2(30) 2. Department information table
Fees number(6) 3. Faculty's Information Table
primarykey (course_id, department_id) 4. Course Information Table
(5) Schedule Type Header Table: schedule_type 5. Schedule Type Header Table
Schedule_Id varchar2(20) 6. Schedule Type Details
Schedule_Description varchar2(50) 7. Class Location Information
8. Class table
(6) Schedule Type Details: schedule_detail
9. Student Grade Information Table
DDL Commands (ALTER) (Any 5)
Alter the Table with the following requirements. 2. Add a primary key for Schedule_Id.
(Hint: Use Alter Table Command) (4) Alter the Schedule Type Details to make the following changes:
 Add a composite primary key to the columns Schedule_id, day.
(1) Alter the student table to make the following changes:  Add a Foreign key to the column Schedule_id which refers
 Add a new column SEX which is of char datatype. schedule_id (Schedule Type Header).
 Alter the column size of First_Name to 25. (5) Alter the Class Table to make the following changes:
 Alter the datatype of Dob to Date  Add a foreign key for the column Schdule_Id which refers
 Add a primary key constraint for the Student Id. schedule(Schedule_Id)
(2) Alter the new column Position in Faculty table which datatype  Add a foreign key for the column Department_Id which refers
varchar2 and size 25 with a check constraint which checks for Department(Department_Id)
‘ASSISTANT PROFESSOR','ASSOCIATE PROFESSOR',  Add a foreign key for the column Course_Id which refers
'PROFESSOR'. Course(Course_Id).
(3) Alter the Schedule Type Header Table to make the following (6) Add the new column hod the data type is varchar2(25) into
changes: depart_info.
1. Reduce the size of the schedule description to 100. (7) Alter table student add column dept_id set as foreign key
DDL COMMANDS Adding Constraints (Any 5)
1. Enable the primary key student_id student table. 5. Drop the foreign key schedule_id in schedule_type_details.
2. Disable the foreign key schedule_id in schedule_type_details table. 6. Add primary key to course table as before.
3. Enable the foreign key fk_class_schedule_id in class table. 7. Add foreign key to schedule_id in the schedule_type_details as
4. Drop the primary key student_id in student table. before.
DML COMMANDS: (Any 5)
1. Insert Records into the following tables. i. Student Grade Information Table.
(Hint: insert minimum 05 records in each table). (2) Display all the inserted records in the each table.
a. Student Information Table. (3) Set save points after every ten insertion.
b. Department Information Table. (4) Roll back to the second save point.
c. Faculty Information Table.
d. Course Information Table. (5) Set save point del.
e. Schedule Type Header Table. (6) Delete records from the faculty table.
f. Schedule Type Details Table. (7) Set save point ins.
g. Class Location Table. (8) Insert a row in the course table.
h. Class Table.
(9) Roll back the transactions till the deletion.
Using SELECT COMMAND (Any 3)
1. Display the Student Id and the Firstname from the Student table 4. Display the eldest male Student's Firstname from the Student table.
who doesn't have a telephone and an email. 5. Display the student's names whose first_name sounds alike.
2. Display Students Firstname, Dob whose Firstname contains 'A' in 6. Display the Facultys Firstname, lastname concatenated together
the Fourth position. and the first character in capitals.
3. Display Students Firstname, Dob whose Birthday falls today.
Using SELECT COMMAND (date function) (Any 3)
1. Display the first day of a given year. 4. Display the greatest date of the two given dates.
2. Display the no of months of the students since their birth. 5. Display the Students Firstname, Dob in the format
3. Display the next date of the given day that immediately follows the "DD/MONTH/YYYY".
sysdate. 6. Display Scheduled Id from the Schedule Type table for which the
starting time is next month and duration is less than three.
Using SELECT COMMAND (Any 3)
1. Display Students Id from the Student table whose Lastnames are 4. Display minimum fees, maximum fees and difference between the
unique. minimum and the maximum fees from the course table.
2. Display Course Id, Department Id from the Course table where the 5. Display Scheduled Id from the Schedule Type for which the starting
fees is the least. time is current day.
3. Display the Course Id, fees from the course table with the fees in 6. Display all from the Class location table substitute the Seating
the format '$999.99'. capacity to 'Not Applicable" if its nul
DML COMMAND (Update) (Any 3)
1. Update all information’s from the Student table whose lastname is 4. Update Students Last Name whose state starts with the letter 'T' to a
null to a last name of 'Nil'. value of 'TTT'.
2. Update Students Last name whose city is Madras to ‘Chennai'. 5. Update the eldest male Student's Last name from the Student table
3. Update Students last name to 'YOUTH' whose age is less than 20. to 'SENIOR'.
DML COMMAND (Delete Function) (Any 5)
1. Delete all information’s from the Student table whose lastname is 4. Delete Students information whose city is Chennai.
null. 5. Delete Students information whose Firstname contains 'A' in the
2. Delete the information from Student table that doesn't have a Fourth position.
telephone and an email. 6. Delete Students information whose Birthday falls on June,05.
3. Delete all information from the Student table where the Students 7. Delete the eldest male Student's information from the Student
Firstname is of only ten characters. table.
DCL Commands (Rollback/ Savepoint/Commit) (Any 5)
1. Rename the student information table as student. 5. Commit the changes.
2. Create a savepoint s1. 6. Disable the primary key constraint of facultys information table.
3. Insert two new student detail in student table. 7. Truncate the employee table.
4. Rollback to savepoint s1. 8. Drop the foreign key constraint.
Using SQL functions like AVG, MAX CASE statements (Any 5)

1. Find the first name of the ‘A’ grade students. 6. Count the number of employee having basic greater than or equal
2. Find the fees of the given department name. to 2000.
3. Count the total number of students in student information table. 7. Count the number of student whose state is TN and august month
4. Calculate the average basic of employee. babies.
5. Determine the minimum and maximum basic of employee; rename 8. Display the name of the faculty in upper case.
the title as max_basic and min_basic respectively.
Creating a View synonym and index (Any 5)
1. Create a view named student from student information and a. Course id.
department information tables that contains only the following b. Department id
columns student_id, first name, last name and department_id. c. Title
2. Create a table dummy with two columns( name, id). d. Description
e. fees
3. Create a sequence instseq with the following specifications
f. Total fees (i.e. units *250 + fees)
minimum value 1, maximum value 20, increment by 1, start with
6. Replace the view class_summary by removing the column title
0, with cycle and cache 10.
from the class table.
4. Alter the sequence such that the maximum value is only 15.
7. Delete the rows from the course_view where deparment id is null
5. Create a view course_view from the course table with the and fees > 100 and total fees less than 500.
following fields.
More Examples on Index (Any 3)
1. Create an index stud_last on the student table (Lastname). 3. Drop index stud_last.
2. Create an unique index dept_name on the department 4. Create a cluster named dept_cluster of datatype number(2).
table(department name).

ASSIGNMENT – 2
Cursors
Note: use the cursor attributes % found, % notfound, % rowcount, % isopen
1. Write PL/SQL block to decrease the fees in the Course table to 5%.
2. Write a PL/SQL block to display the schedule_id, schedule_description, day, starting_time, and duration from the schedule_type header,
schedule_type details tables.

Database Triggers. (Any 4)


(1) Write a database trigger before insert for each row on the course table not allowing transactions on Sundays and Saturdays.
(2) Write a database trigger after update for each row giving the date and the day on which the update is performed on the class table.
(3) Write a database trigger before delete for each row not allowing deletion and giving message on the department table.
(4) Write a database trigger after delete for each row on faculty table, which creates a new table named dump for the first delete, and inserts the
deleted row into that table.
(5) Write a database trigger before insert/delete/update for each row not allowing any of these operations on the table student on Mondays.
Wednesdays, Sundays.
(6) Write a database trigger before insert/delete/update for each row not allowing any of these operations on the table faculty between 6.p.m to 10
a.m

PL/SQL programming (Any 4)

1. Write PL/SQL block to increase the salary by 10% if the salary is > 2500 and > 3000.
2. Write PL/SQL block to decrease the salary by 13% if the salary is >3000 and < 5000.

While Loops. (Hint: use basic loops, while loops, numeric for loops, cursor for loops.)
1. Write PL/SQL block to insert student details into student table until the user wishes to stop.
2. Write PL/SQL block to display the male employees details.
3. Write PL/SQL block to display the total salary (I,e.Salary +Comm) of each employee whose comm. Is not null.
4. Write PL/SQL block to display the total salary (I,e .Salary + Comm.) of each employee whose comm. Is not null until sum of total salary exceeds
25,000.
5. Write PL/SQL block to display the employee details from the employee table, and get the user’s choice and delete the record if the user wishes to
delete.

Sub programs & packages (Any 3)

1. Create a procedure that takes an argument (description) and deletes the row from the course table.
2. Create a procedure that displays the faculty details, class details and the student details of a particular student which the user inputs.
3. Write a function that takes two arguments viz. student_id, class_id from the user and checks whether any conflict occurs with any
4. Others class with the current class schedule. If occurs give an alert message that a conflict occurs with the corresponding class else display no
conflict.
5. Write a function that will display the constraint details in the given table.

Creating a relation from existing tables


(1) Create master detail relations for student and student grade table. Student information table is the master table and student grade table is the detail
table it gives the grade detail of the course.
(2) Create a master detail relation for schedule header and schedule type tables.

Assignment – III

ER – Diagram Assignment
1. Draw an ER diagram to capture the requirements as stated below:

A database is needed to capture information pertaining to the running of various clubs by the recreation cell of an institution.
• Details such as name, date of birth, gender are needed for each member.
• Club details are needed such as the activity type (oratorical, music, dance, instrumental music etc) and contact phone number.
• Team details required to include team name and the days on which the team practices.
• Tutor details such as tutor name, address and telephone number are also needed, along with details of the skill each tutor is qualified in.
• Rules governing the involvement of members and tutors in the teams and clubs are as follows:

o Members may head only one team and every team has to have a head. Tutors teach at least one team and every team has at least one tutor.
o Every member must belong to at least one team and each team has a number of members.
o Every team must belong to a club and clubs must have at least one team.
o Every club has a member who is the president but a member may only be president of one club.

Draw the ER Diagram for the above requirement. Map the ER diagram to the Relational Model. Create tables identified and insert five tuples
in each of the tables created. The students are required to carefully take care of the constraints on each of the table.

2. Draw the ER-Diagram For Given Schema

DEPT: DEPTNO (NOT NULL, NUMBER (2)), DNAME (VARCHAR2 (14)), LOC (VARCHAR2 (13)

EMP:EMPNO (NOT NULL, NUMBER (4)), ENAME (VARCHAR2 (10)), JOB (VARCHAR2 (9)), MGR (NUMBER (4)), HIREDATE
(DATE), SAL (NUMBER (7, 2)), COMM (NUMBER (7, 2)), DEPTNO (NUMBER (2))
MGR is the empno of the employee whom the employee reports to. DEPTNO is a foreign
SQL ASSIGNMENT IV
EMPLOYEE DATABASE – I
Table
Dept (dept_id,dept_name,manager_id,loc_id)
Emp (emp_id,first_name,last_name,email,phone,hire_date,job_id,salary,commission_pct, manager_id,dept_id)
This assignment has two sets A and B. Both have same tables

SET – A OF EMPLOYEE DATABASE – II


Queries
1. The HR department needs a query to display all unique job codes from the EMPLOYEES table.
(HINT: like account, manager, asst, president, VP, clerk etc)
2. Thes for its report on employees. Name the column headings Emp #, Employee, Job, and Hire Date, respectively.
3. Change the salary to $1,000 for all employees who have a salary less than $900.
4. The HR department has requested a report of all employees and their job IDs. Display the last name concatenated with the job ID (separated by a
comma and space) and name the column Employee and Title.
5. Due to budget issues, the HR department needs a report that displays the last name and salary of employees who earn more than $12,000.
6. The HR department wants to determine the names of all employees who were hired after Davies. Create a query to display the name and hire date
of any employee hired after employee Davies.
7. Create a report that displays the last name and department number for employee number 176.
8. The HR departments needs to find high-salary and low-salary employees. display the last name and salary for any employee whose salary is not
in the range of $5,000 to $12,000.
9. Produce a list of jobs for departments 10, 50, and 20, in that order. Display job ID and department ID using set operators.
10. Create a report to display the last name, job ID, and start date for the employees with the last names of Matos and Taylor. Order the query in
ascending order by start date.
11. The HR department needs a report to display the employee number, last name, salary, and salary increased by 15.5% (expressed as a whole
number) for each employee. Label the column New Salary.

SET – B OF EMPLOYEE DATABASE – II


1. Write a query that displays the last name (with the first letter uppercase and all other letters lowercase) and the length of the last name for all
employees whose name starts with the letters J, A, or M. Give each column an appropriate label. Sort the results by the employees’ last names.
2. Create a query to display the last name and salary for all employees. Format the salary to be 15 characters long, left-padded with the $ symbol.
Label the column SALARY.
3. Find the highest, lowest, sum, and average salary of all employees for each job type. Label the columns Maximum, Minimum, Sum, and Average,
respectively. Round your results to the nearest whole number.
4. The HR department needs a report on job grades and salaries. To familiarize yourself with the JOB_GRADES table, first show the structure of
the JOB_GRADES table. Then create a query that displays the name, job, department name, salary, and grade for all employees.
5. Create a report that displays the employee number, last name, and salary of all employees who earn more than the average salary. Sort the results
in order of ascending salary.
6. The HR department needs a report that displays the last name, department number, and job ID of all employees whose department location ID is
1700.
7. The HR department needs a list of department IDs for departments that do not contain the job ID ST_CLERK. Use set operators to create this
report.
8. Change the last name of employee 3 to Drexler.
9. The staff in the HR department wants to hide some of the data in the EMPLOYEES table. They want a view called EMPLOYEES_VU based on
the employee numbers, employee names, and department numbers from the EMPLOYEES table. They want the heading for the employee name
to be EMPLOYEE.
10. The HR department needs a report that displays the last name and hire date for all employees who were hired in 1994.
11. Department 50 needs access to its employee data. Create a view named DEPT50 that contains the employee numbers, employee last names, and
department numbers for all employees in department 50. You have been asked to label the view columns EMPNO, EMPLOYEE, and DEPTNO.

DATABASE – II
Consider the following three tables – SAILORS, RESERVES and BOATS

having the following attributes SAILORS (Salid, Salname, Rating, Age)


RESERVES (Salid, Boatid, Day)
BOATS (Boatid, Boat-name, Color) Use the above schema and solve the queries using SQL
i) Find the name of sailors who reserved green boat.
ii) Find the colors of boats reserved by “Ramesh”
iii) Find the names of sailors who have reserved a red or green boat.
iv) Find the Sailid’s of sailors with age over 20 who have not registered a red boat.

DATABASE – III
Consider the following relational database schema:

STUDENT ( Student_id, Sname, Major, GPA) FACULTY (Faculty_id, fname, dept, designation, salary) COURSE (Course_id, Cname, Faculty_id)
ENROL (Course_id, Student_id, grade) Use the above schema and solve the queries using SQL
i) List the names of all students enrolled for the courses “CS-53”
ii) List the names of students enrolled for the courses “CS-53” and have received “A” grade.
iii) List all the departments having an average salary of above Rs20,000.
iv) Give a 15% raise to salary of all faculty.
v) List the names of all faculty members beginning with “R” and ending with letter “U”.

DATABASE – IV
Consider the following relational database schema:

CUSTOMER (CUST_ID, CUST_NAME, ANNUAL_REVENUE, CUST_TYPE) CUST_ID must be between 100 and 10,000
ANNUAL_REVENUE defaults to $20,000 CUST_TYPE must be manufacturer, wholesaler, or retailer SHIPMENT (SHIPMENT_#, CUST_ID,
WEIGHT, TRUCK_#, DESTINATION, SHIP_DATE) Foreign Key: CUST_ID REFERENCES CUSTOMER, on deletion cascade Foreign Key:
TRUCK_# REFERENCES TRUCK, on deletion set to null Foreign Key: DESTINATION REFERENCES CITY, on deletion set to null WEIGHT
must be under 1000 and defaults to 10 TRUCK (TRUCK_#, DRIVER_NAME) CITY (CITY_NAME, POPULATION)
Perform the following queries:
a) What are the names of customers who have sent packages (shipments) to Sioux City?
b) What are the names and populations of cities that have received shipments weighing over 100 pounds?
c) List the cities that have received shipments from customers having over $15 million in annual revenue.

DATABASE – V
Consider the following relational database schema:

CUSTOMER (CUST_ID, CUST_NAME, ANNUAL_REVENUE, CUST_TYPE) CUST_ID must be between 100 and 10,000
ANNUAL_REVENUE defaults to $20,000 CUST_TYPE must be manufacturer, wholesaler, or retailer
SHIPMENT (SHIPMENT_#, CUST_ID, WEIGHT, TRUCK_#, DESTINATION, SHIP_DATE) Foreign Key: CUST_ID REFERENCES
CUSTOMER, on deletion cascade Foreign Key: TRUCK_# REFERENCES TRUCK, on deletion set to null Foreign Key: DESTINATION
REFERENCES CITY, on deletion set to null WEIGHT must be under 1000 and defaults to 10
TRUCK (TRUCK_#, DRIVER_NAME) CITY (CITY_NAME, POPULATION).
Perform the following queries:
a) What are the names of customers who have sent packages (shipments) to Sioux City?
b) What are the names and populations of cities that have received shipments weighing over 100 pounds?
c) List the cities that have received shipments from customers having over $15 million in annual revenue.
Pl/Sql Lab Assignment
Create assignment assuming appropriate tables
1. WAP in PL/SQL for addition of 1 to 100 numbers.

2. WAP in PL/SQL to inverse a number, e.g. 5467 must be inverted to 7645.

3. WAP in PL/SQL for changing th eprice of product ‘p00001’ to 7000 if it’s price is less then 7000 and update this transation by updating the table.

4. Create a view which shows the detail of salesman with his salary. (Salesmanname, salary)

5. Create a trigger on sailors table after updating a row into table.

6. Write the pl/sql program to find division of two numbers and store it in a table?

7. WAP in pl/sql to implement whether the given number is palindrome or not

8. WAP in PL/SQL to write a Cursor to display the list of employee and total salary departmentwise.

9. WAP in PL/SQL to write a Cursor to display the list of employees who are working as Managers or Analystst.

10. Write a Trigger to ensure that Dept table does not contain duplicate of null values in Deptno column.

You might also like