CS3481 - LAB Exercises
CS3481 - LAB Exercises
LAB EXERCISES
EX 1:
create a database table, add constraints (primary key, unique, check, Not null), insert rows,
update and delete rows using SQL DDL and DML commands.
Q2: Add a column experience to the emp table. experience numeric null is allowed.
Q3: Modify the column width of the job field of emp table.
Q4: Create dept table with the following structure.
Name Type
------------ ---------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(10)
LOC VARCHAR2(10)
Deptno as the primary key
Q5: Create the emp1 table with ename and empno, add constraints to check whether the
empno value while entering is greater than 100 (i.e) empno >100.
Q6:Drop a column experience from the emp table
Q7: Truncate the emp table
Q8: Insert more records into the employee table.
Q9: Insert a single record into dept table.
Q10: Update the emp table to set the salary of all employees to Rs 20,000
Q11: Delete only those who are working as “Lecturer”
EX 2: FOREIGN KEY CONSTRAINT AND REFERENTIAL INTEGRITY
AIM:
To Create a set of tables, add foreign key constraints and incorporate referential integrity
1. Create table sailor(sid,sname,age).Add trigger before insert to allow age greater than 18
2. Create table stock(pid ,stock). Add trigger before update to maintain a stock above 5 on
update.
3. Write a Trigger to carry out the following action: on deleting any records from the emp
table ,the same values must be inserted into the log table.
1. Create a view containing the employee number and employee name from employee
table.
2. Create an index on employee name and then run the query. Use set timing on to check
for the elapsed time to execute the query.
3. Update the employee name of an employee and record the observations. Check if the
value is reflected in the original table.
EX 10 : SQL QUERIES
1. List of Students in a Particular Department
Write a query to find all students who belong to the "Computer Science" department.
2. List of Professors by Department
Write a query to list all professors and their respective departments.
3. Courses Taught by a Professor
Write a query to find all courses taught by Professor Sarah Lee.
4. Total Credits per Student
Write a query to calculate the total number of credits a student has taken, based on
their enrollments.
5. List of Students Enrolled in a Specific Course
Write a query to find all students who are enrolled in the "Data Structures" course.
6. Average Grade per Course
Write a query to calculate the average grade (A = 4, B = 3, C = 2, etc.) for each course.
7. Students with GPA Greater Than 3.5
Write a query to list all students whose GPA (based on their courses) is greater than
3.5.
8. Top 3 Best Performing Students
Write a query to find the top 3 students with the highest GPA (average grade across all
their courses).
9. Professor's Course Load
Write a query to find the number of courses taught by each professor.
10. List of Upcoming Events
Write a query to list all events that are happening after the current date.
11. Student Enrollment History
Write a query to display the courses each student has enrolled in, along with their
grades.
12. Total Number of Students per Department
Write a query to find the number of students in each department.
13. Students Who Have Failed a Course
Write a query to find all students who have received a grade of "C" or below in any
course.
14. Department-wise Average Credits per Course
Write a query to calculate the average number of credits for each department.
15. Courses Not Taught by Any Professor
Write a query to find all courses that are not assigned to any professor.
16. Find the Professors Who Have Taught More Than One Course
Write a query to list the professors who have taught more than one course.
17. List Events Happening in a Specific Location
Write a query to list all events that are happening in the "Main Hall."
18. Students and Their Professors
Write a query to list all students along with the professors teaching their enrolled
courses.
19. Courses with More Than 50 Students Enrolled
Write a query to find all courses that have more than 50 students enrolled.
20. Departments with the Most Courses
Write a query to find which department offers the most number of courses.