Vellore Institute of Technology School of Computer Science and Engineering Database Systems Lab Mid-term Exam Question Slot – L3+L4 1. Consider the following relational schema for the Office of the Controller of Examinations Application. Student (Rollno, Name, Dob, Gender, Doa, Bcode); Implement a check constraint for Gender Date of Admission Branch (Bcode, Bname, Dno); Department (Dno, Dname); Course (Ccode, Cname, Credits, Dno); Branch_Course (Bcode, Ccode, Semester); Enrolls (Rollno, Ccode, Sess, Grade); For Example, SESS can take values ‘APRIL 2013’, ‘NOV 2013’ Implement a check constraint for grade Value Set (‘S’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘U’ ); Students are admitted to Branches and they are offered by Departments. A branch is offered by only one department. Each branch has a set of Courses (Subjects). Each student must enroll during a semester. Courses are offered by Departments. A course is offered only by one department. If a student is unsuccessful in a course he/she must enroll for the course during next session. A student has successfully completed a course if the grade obtained by is from the list (A, B, C, D, and E). A student is unsuccessful if he/she have grade ‘U’ in a course. Primary Keys are underlined. Questions Create all the tables or database files mentioned above and populate the table with your own data. Perform the following questions. Question (A) Develop a SQL query to list details of Departments that offer more than 3 branches. Question (B) Develop a SQL query to list the details of Departments that offer more than 6 courses. Question (C) Develop a SQL query to list the details of courses that are common for more than 3 branches. Question (D) Develop a SQL query to list students who got ‘S’ in more than 2 courses during single enrollment. Question (E) Create a view that will keep track of the roll number, name and number of courses, a student has completed successfully. 2. Consider the following relational schema Staff (Staffno number (5), Name varchar2 (30), Dob Date, Gender Char (2), Doj Date, Designation varchar2 (30), Basic_pay number (6), Deptno varchar2 (5)); Gender must take value ‘M’ or ‘F’. Dept (Deptno varchar2 (5), Name varchar2 (30)); Skill (Skill_code varchar2 (5), Description varchar2 (30), Charge_Outrage number (3)); Staff_skill (Staffno number (5), Skill_code varchar2 (5)); Project (Projectno varchar2 (5), Pname varchar2 (5), Start_Date Date, End_Date Date, Project_Manager_Staffno number (5)); Project Number must start with ‘P’. Works (Staffno number (5), Projectno varchar2 (5), Date_Worked_On Date, Intime Timestamp, Outtime Timestamp); Primary Key is underlined. Questions Create all the tables or database files mentioned above and populate the table with your own data. Perform the following questions. Question (A) Develop DDL to implement the above schema specifying appropriate data types for each attributes and enforcing primary key, check constraints and foreign key constraints. Question (B) Populate the database with rich data set. Question (C) Develop a SQL query to list the departmentno and number of staff in each department, Question (D) Develop a SQL query to list the details of staff who earn the AVG basic pay of all staff. Question (E) Develop a SQL query to list the details of staff who have more than 3 skills. Question (F) Develop a SQL query to list the details of staff who have skills with a charge outrate greater than 60 per hour. Question (G) Create a view that will keep track of the department number, department name, the number of employees in the department and total basic pay expenditure for the department. Question (H) Develop a SQL query to list the details of Depts which has more than 5 staff working in it. Question (I) Develop a SQL query to list the details of staff who have more than 3 skills. 3. Database Schema for a Student Library scenario Student(Stud_no : integer, Stud_name: string) Membership(Mem_no: integer, Stud_no: integer) Book(book_no: integer, book_name:string, author: string) Iss_rec(iss_no:integer, iss_date: date, Mem_no: integer, book_no: integer) For the above schema, perform the following— a) b) c) d) e) f) g) h) i) Create the tables with the appropriate integrity constraints Insert around 10 records in each of the tables List all the student names with their membership numbers List all the issues for the current date with student and Book names List the details of students who borrowed book whose author is CJDATE Give a count of how many books have been bought by each student Give a list of books taken by student with stud_no as 5 List the book details which are issued as of today Create a view which lists out the iss_no, iss _date, stud_name, book name 4. Database Schema for a Employee-pay scenario employee(emp_id : integer, emp_name: string) department(dept_id: integer, dept_name:string) paydetails(emp_id : integer, dept_id: integer, basic: integer, deductions: integer, additions: integer, DOJ: date) payroll(emp_id : integer, pay_date: date) For the above schema, perform the following— a) b) c) d) e) f) g) h) i) Create the tables with the appropriate integrity constraints Insert around 10 records in each of the tables List the employee details department wise List all the employee names who joined after particular date List the details of employees whose basic salary is between 10,000 and 20,000 Give a count of how many employees are working in each department Give a names of the employees whose netsalary>10,000 List the details for an employee_id=5 Create a view which lists out the emp_name, department, basic, dedeuctions, netsalary 5. Database Schema for a student-Lab scenario Student(stud_no: integer, stud_name: string, class: string) Class(class: string, descrip: string) Lab(mach_no: integer, Lab_no: integer, description: String) Allotment(Stud_no: Integer, mach_no: integer, dayof week: string) For the above schema, perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the machine allotments with the student names, lab and machine numbers d) List the total number of lab allotments day wise e) Give a count of how many machines have been allocated to the ‘CSIT’ class f) Give a machine allotment etails of the stud_no 5 with his personal and class details g) Count for how many machines have been allocatedin Lab_no 1 for the day of the week as “Monday” h) How many students class wise have allocated machines in the labs i) Create a view which lists out the stud_no, stud_name, mach_no, lab_no, dayofweek 6. Below are the details of Employees working for a software Company. Create the table called EmpDetails with the below mentioned details. Eid (Primary Key) E101 E102 E103 E104 E105 E106 E107 E108 Ename DOB Designation Salary DOJ Suma Amit Payal Kiran Meenal Sheila Swamy Sushma 29-Dec-89 10-Jan-95 15-Aug-85 20-Apr-90 29-May-83 1-May-70 13-Jan-85 22-Dec-76 Designer Programmer Tester Programmer DBA Analyst Programmer DBA 01-Apr-10 18-Feb-18 13-Jun-11 7-Mar-14 9-Dec-11 25-Sep-18 14-Feb-16 31-Jan-12 20000 25000 35000 40000 50000 60000 45000 45000 a. Write sql query to display all the employees whose designation is Programmer. b. Write sql query to display employees who have joined after 2014. c. Write sql query to display all the employees whose name ends with ‘a’. d. Write sql query to display the total salary of all the employees whose designation is programmer. e. Write sql query to display all the employee names in upper case. f. Write sql query to display the details of the employee with highest experience. g. Write sql query to display the details of the employees whose name contains ‘ee’. h. Write sql query to increase the salaries of employees by 5000 whose designation is DBA. i. Write sql query to display the employees whose salary is more than the average salary of all the employees. j. Write sql query to display the record in the following format: xxxxxxxxx is working as xxxxxxxxxxxxxx with a Salary of Rs.xxxxxxxx eg: Suma is working as Designer with a Salary of Rs. 20000 7. Below are the details of Students enrolled in various course of B.Com Create the table called Student with the below mentioned details. Sid (Primary Key) 1001 1002 1003 Sname DOB State Gender Category Course Neha Arun Payal 29-Dec-02 10-Jan-02 15-Aug-01 F M F Gen OBC Gen Comp Honors Appl 1004 1005 Amrita Pavan 20-Apr-02 29-May-03 F M Anchal Ramya Rakesh 1-May-03 13-Jan-02 22-Dec-01 OBC ExService men OBC Gen Sports Honors Comp 1006 1007 1008 Telangana Telangana Maharashtr a Karnataka AndhraPrad esh Gujarat Telangana AndhraPrad esh F F M Comp Appl Comp a.. Write sql query to display the students who are not from Telangana or AndhraPradesh. b. Create a view to display the columns Sid, Sname for students belonging to Telangana. c. Write sql query to create an index on column Sname. d. Write sql query to display all the female students enrolled under Comp course and who belong to OBC. e. Write sql query to display the student ids, names, and their present age. f. Write sql query to display the students in the ascending order of their names for each course. g. Write sql query to delete all the students records who have enrolled for Comp course and who are born after 2002. h. Write a sql query to add two new columns Contactno and Email to the existing fields. i. Writs an sql query to display all the Student names prefixed with Mr./Ms. Based on Gender column. j. Write an sql query to display all the Student names where the length of the name is 5 characters.