Course: CS691- Database Management System Lab PROGRAMME: COMPUTER SCIENCE & ENGINEERING DEGREE:B. TECH COURSE: Database Management System Lab SEMESTER: VI CREDITS: 2 COURSECODE: CS691 COURSE TYPE: Practical COURSE AREA/DOMAIN: Laboratory Skills CONTACT HOURS: 3 (weeks) CORRESPONDING Theory COURSE CODE : CS601 THEOTY COURSE NAME: DATABASE MANAGEMENT SYSTEM Course pre-requisites CODE COURSE NAME DESCRIPTION SEM Course Objectives 1. To develop conceptual understanding of database management system 2. To understand how a real world problem can be mapped to schemas 3. To develop understanding of different applications and constructs of SQL PL/SQL Course Outcomes 1. Ability to crate database tables 2. Ability to formulate SQL queries based on the problems given 3. Ability to apply PL/SQL Lab Outcomes addressed in this course I.1. Develop students understanding through laboratory activities to solve problems related to key concepts taught in the classroom. L2. Develop students ability to solve open ended problems through the design and construction of new artifacts or processes. L3. Develop debugging capability in order to propose and apply effective engineering solutions. Department of CSE Page 1
Syllabus Creating Database Creating a Database Creating a Table Specifying Relational Data Types Specifying Constraints Creating Indexes 2. Table and Record Handling INSERT statement Using SELECT and INSERT together DELETE, UPDATE, TRUNCATE statements DROP, ALTER statements 3. Retrieving Data from a Database The SELECT statement Using the WHERE clause Using Logical Operators in the WHERE clause Using IN, BETWEEN, LIKE, ORDER BY, GROUP BY and HAVING Clause Using Aggregate Functions Combining Tables Using JOINS Subqueries 4. Database Management Creating Views Creating Column Aliases Creating Database Users Using GRANT and REVOKE 5. Oracle PL SQL Cursors in Oracle PL / SQL Writing Oracle PL / SQL Stored Procedures Department of CSE Page 2
Gaps in the syllabus - to meet industry/profession requirements S.NO. DESCRIPTION 1 Knowledge of other basic objects like inbuit and use defined functions and triggers Knowledge of how to handle Exceptions Skill of mapping a problem statement to ER diagram and then making the schema PROPOSED ACTIONS Extra Assignments LO MAPPING L1, L2,L3 Topics beyond syllabus/advanced topics S.NO. DESCRIPTION HOURS Introduction to different in built functions Introduction to function and trigger 1 Introduction to Exception Handing Modeling a real work problem to data base tables 9 Design Student Attendance System ( Project). Web Source References S.NO. 1 Delivery/Instructional Methodologies URL http://docs.oracle.com/cd/e11882_01/nav/portal_5.htm S.NO. DESCRIPTION 1 Chalk and Talk 2 PPTs, Lab demos Assessment Methodologies S.NO. DESCRIPTION TYPE 1 Student Assignments. Direct 2 Lab Tests Direct 3 University Examination Direct 4 Student Feedback Indirect Department of CSE Page 3
Assignment Lists Assignment 1 : 1. Complete schema design for a student attendance system 2. It should have entity for class, student, subject, routine, attendance 3. Create proper primary key and foreign keys 4. Write notes on Temporary table and Global Temporary table 5. Give an example where CATS will be necessary, with necessary syntax 6. Give a listing of the tables, columns and constraints Assignment 2: 7. write query to select all the columns of emp table 8. write query to select only Empname, Ename and Job 9. write query to select unique Jobs 10. write query to select only those employees who are salesman 11. select employee name, grade and salary, in the order of their salary 12. Mgmt is considering a pay raise, however they want to find out, if they give a flat 200$ increment to all, then what % each person is getting. So in your result display, ename, salary and pctincr 13. Express work experience of each of the employeses by using sysdate and hiredate in terms of no of years. Hints : you would need to use cast 14. select only those employees who are a clerk and a manager. Use all of or condition, IN and NOT IN clause a. Comment on the case sensitivity of the string literal within single quote 15. use emp table and use different columns and string concatenation to display a message like below for each of the employees Department of CSE Page 4
b. Output Example : c. JAMES is a CLERK and is working in the company for last 32 Years 16. use emp table to display only those employees who have joined in the year 80 and 81. d. Comment on if between clause is inclusive or exclusive 17. Use like statement to display name of the employees which start with A i. Write your remarks on use of wildcards with like statement 18. Select those employees, who has joined on or before 31 st December 1982 and is either a clerk or having a salary greater than 2500 Assignment 3: 19. List down no of employees, minimum salary, maximum salary for each department 20. Update Email_id, if department id is a) < 1000 update the EMAIL field by appending @oracle.com b) < 5000 update the EMAIL field by appending @oracle.co.uk c) Else update it as oracle.co.in 21. Apart from Delete a Truncate statement can also be used for deleting the rows. Comment on their difference. 22. Display a department id wise count of employees a. Getting salary more than 5000 b. Apart from the above condition, select only those departments which has an average salary in excess of 6500 23. Explain how two levels of filtering is happening based on firstly where clause secondly having clause based on this particular scenario 24. You want to add a new row in the employees table with employee id 10000, First Name = Scott, Last Name = Tiger, Email = Stiger, Hire Date, 01/02/2014, Job id PR_Prsdnt ( Title Company President ) Department_id 280 ( Department_Name Database ) Salary 50000 25. Issue necessary insert statements. 26. After the update is over in the email column, use instr and substr to display email id and domain information separately. 27. Display day, month and year of the hire date of the employees Department of CSE Page 5
28. Display the last name of the employees in a manner, so that they are right aligned. However please make sure the last name is displayed in a manner, so that they are sorted in descending order by the no. of character in each name 29. Select an appropriate query which displays the fistname and lastname of all the employees, however if the fisrstname is not available display it as Unknown 30. If an employee have spent less than 5 years then he is considered entry level id 5 10 then midlevel else a senior employee. Write a query, which will label the employees in either of the above categories 31. Write query to find out any departments that are present in department table but does not have employees 32. Write a query which will display job id, which are present in both job and employee columns Assignment 4: 33. Display name of employees, department name and job name for each employee 34. Display the department name along with no of employees and average salary of that department 35. For each department, find out no. of jobs the employees are assigned to. 36. Check for correctness of the above queries in terms of count, if you want to bring in all entries, how would you achieve the same? 37. Group by the employees based on the first character of employee first name. Display the results in alphabetic order (descending) of first character. 38. Display name of those employees who get a salary more than the average salary 39. Display name of the all the employees who are stock manager, except the one who gets the minimum salary. 40. Display firstname,lastname,salary of those sales representatives who earns a higher salary than the minimum salary a sales manager receives. 41. Display the name of the employees/employee who gets the second highest salary. (sub query) 42. Come up with the query for previous question using set operators 43. Display the name of the employee (manager) who has the maximum no. of employees reporting to him. Department of CSE Page 6
44. Display the name of those employees, who are in the same department as Timothy Gates and gets an salary more than the average salary of all the employees 45. If an employee have spent less than 5 years then he is considered entry level id 5 10 then midlevel else a senior employee. Write a query, which will label the employees in either of the above categories 46. Write query to find out any departments that are present in department table but does not have employees 47. Write a query which will display job id, which are present in both job and employee columns 48. Increase salary of each employee of all the department who draws the minimum salary by 100$. Assignment 5: 49. Create a function which takes two parameters tablename and columnname and returns second max value of the columns. Assignment 6: 50. Write a simple procedure, which executed now will return the time that of two hours earlier. 51. For emp table in scott, write a stored procedure that creates a table for each unique department_id and stores the employee records that belong to that particular department. 52. Write a stored procedure that expects one parameter no and based on the no it shows that many name of employees in terms of salary they are getting. 53. Write a simple procedure, similar to previous assignments, given an email id, this displays username and domain respectively, have correct messages displayed. Assignment 7: 54. Modify the procedure that takes salary and returns the name, handle the exception so that if user gives a nonnumeric value this exits gracefully. 55. Create a table books, which has columns as bookid and bookname. Insert two rows with booknames database fundamentals and database technologies. Use a sequence to populate the bookid for both the rows. 56. There is a circular from federal govt. no employees can get salary less than 1000$. So in case some employees are being inserted in the table with salary less than 1000 automatically this should be updated to 1000, Write a trigger for the same. Do it first by a just changing the below in insert before, and also by an update command after insert is done. 57. Create a trigger on emp table such that when a new employee is inserted with a deptno that is new, first insert that record in department and then insert the same in emp to avoid foreign key error. 58. Create a view, which hides the salary column from the user. Department of CSE Page 7
59. Create a view which has ename and dname respectively, check if you can update/insert into the views, justify your results Lesson Plan: S.NO. DESCRIPTION 1 Different Types of Data, Creating Tables, Data Types, Constraints, Data Dictionary 2 Select, Insert, Delete, Update, Dual 3 Group By, Having Clause, Different Set Operators 4 Different Types of Joins, Subquery 5 Introduction to PL/SQL, Basic Stored Procedures and functions 6 Stored Procedure Continued 7 Exceptions, Cursors, For Loop 8 Trigger, Sequence, Row ID, Rownum, Views 9 Project Department of CSE Page 8