Assignment - 1 Lab Exercises: DDL Commands Creating A Table Lab-01
Assignment - 1 Lab Exercises: DDL Commands Creating A Table Lab-01
Lab Exercises
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.
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.
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.
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.
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
DATABASE – II
Consider the following three tables – SAILORS, RESERVES and BOATS
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.
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)
6. Write the pl/sql program to find division of two numbers and store it in a table?
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.