Consider the following employee database schema:
EMPLOYEE (ESSN, ENAME, DEPT_NO, SALARY) DEPENDENT (ESSN, DEPEND_NAME, RELATION, DOB) DEPARTMENT (DEPT_NO, DEPT_NAME, MANAGER)
Consider the following employee database schema:
EMPLOYEE (ESSN, ENAME, DEPT_NO, SALARY)
DEPENDENT (ESSN, DEPEND_NAME, RELATION, DOB)
DEPARTMENT (DEPT_NO, DEPT_NAME, MANAGER)
(a) mysql code to Create the appropriate database.
(b) Perform following queries using SQL:
(i) Find details of dependents for employee having name AJAY.
(ii) Find the name of the manager of the department in which employee with ESSN Code 5078 works.
(iii) Find the name of all employees whose age is less than 18 years.
(iv) Find the DOB of the son of the employee having employee code ESSN 5078.
(v) Find the details of the departments in which the employee having employee code ESSN 5078 has worked.
(c) Create the procedures for the above queries.
(d) Write appropriate triggers, exceptions and functions for the above employee database schema.
(a) Code to Create the appropriate database:
CREATE DATABASE EmployeeDB;
USE EmployeeDB;
CREATE TABLE EMPLOYEE (
ESSN INT PRIMARY KEY,
ENAME VARCHAR(255),
DEPT_NO INT,
SALARY DECIMAL(10,2)
);
CREATE TABLE DEPARTMENT (
DEPT_NO INT PRIMARY KEY,
DEPT_NAME VARCHAR(255),
MANAGER VARCHAR(255)
);
CREATE TABLE DEPENDENT (
ESSN INT,
DEPEND_NAME VARCHAR(255),
RELATION VARCHAR(255),
DOB DATE,
FOREIGN KEY (ESSN) REFERENCES EMPLOYEE (ESSN)
);
(b) i. Find details of dependents for employee having name AJAY.
SELECT DEPENDENT.ESSN, DEPEND_NAME, RELATION, DOB
FROM EMPLOYEE, DEPENDENT
WHERE EMPLOYEE.ESSN = DEPENDENT.ESSN
AND ENAME = 'AJAY';
(b) ii. Find the name of the manager of the department in which employee with ESSN Code 5078 works.
SELECT DEPARTMENT.MANAGER
FROM EMPLOYEE, DEPARTMENT
WHERE EMPLOYEE.DEPT_NO = DEPARTMENT.DEPT_NO
AND ESSN = '5078';
(b) iii. Find the name of all employees whose age is less than 18 years.
SELECT EMPLOYEE.ENAME
FROM EMPLOYEE, DEPENDENT
WHERE EMPLOYEE.ESSN = DEPENDENT.ESSN
AND DATEDIFF(CURDATE(), DOB) / 365 < 18;
(b) iv. Find the DOB of the son of the employee having employee code ESSN 5078.
SELECT DOB
FROM DEPENDENT
WHERE ESSN = '5078'
AND RELATION = 'SON';
(b) v. Find the details of the departments in which the employee having employee code ESSN 5078 has worked.
SELECT DEPARTMENT.DEPT_NO, DEPT_NAME, MANAGER
FROM EMPLOYEE, DEPARTMENT
WHERE EMPLOYEE.DEPT_NO = DEPARTMENT.DEPT_NO
AND ESSN = '5078';
(c) Here is the sample SQL code for creating procedures for the above queries in MySQL:
-- Procedure to find the
____ __________ ________ ___ _________.
_________ _______ _____ ________ _________.
____ __________ ___ ______ __________ _____ _________ _______ ______.
_____ ___ ________ __________ ________.
_____ _____ ___ _______ ____ ______ _____ _____ ________ ____.
___ __________ ___ _________ ___ _______ _____ _____ ____ ________ _________.
________ _______ _________ __________ _____ ____ ________ _____ ___ _______ ______ ________.
__________ _________ _______ _____ ______ __________ _______ ___ _____ ________ ___ ______.
___ __________ _____ _____ _____ ____ ______ _________.
________ ___ ______ ______ _______ ___ _________ __________ ______ ____.
__________ ____ __________ __________ __________ _______ _________ ______ _______.
________ _____ ___ _____ _________.
_____ _________ ____ ________ ____ ___ _________.
______ ________ ______ _________ __________.
__________ _______ __________ ____ _______ ___ ____ ______ _______.
_________ ____ _________ _____ _____ ________ ________ __________ __________ _______.
_________ _______ ________ ______ ____.
________ _______ __________ ________ ________ __________ _____ ________ __________ ___ ________.
_________ ________ ______ _______ ______ _________.
_______ _____ __________ _____ ______ ___ ___ ______ _____ ____ ___ __________.
__________ __________ __________ _______ ______.
________ ______ ______ _________ ___ _________ _____ ______ ____ _________.
_________ _________ ______ ________ _________ _______.
____ ____ _________ _____ ___ _________ ___ ___ ________ ___.
_____ ________ ____ _______ _____ ____ ____ ____.
___ ________ _____ _____ ___ ______ ________ _____ ___ ______ _____ ________.
______ _____ ______ _________ ______ _______ _______.
______ _______ __________ ______ ________ ___ ____ ___ ________.
_____ ___ ___ ________ _______ ________ _____ _____.
_________ _____ _________ _____ ______ _________ ___ __________.
_________ ____ ______ ________ ______ ______ ________ __________ __________.
_________ _________ _____ __________ _____ _____ ____ ________.
____ __________ ____ ______ _________ _______ ________.
___ __________ ________ _________ _________ ______ _________ ______ _____ ____ _______.
_______ _____ ______ __________ __________ ____ ________ ___ ____ _______ __________.
_______ ______ ____ _______ ______ _______ ________ _______ __________ ________ ________ ________.
________ __________ ____ _________ _______.
______ ________ _______ _______ ______ ____ _______ _____ _________ ___ __________.
_______ ______ _________ _________ ____ __________.
_________ _________ __________ ________ ____ __________ _________ __________ ______ _____ ______ ___.
_____ __________ __________ __________ _______ ____.
______ ___ _______ ________ _________ ____ __________.
________ _______ ______ __________ _______ ___ ______ ________ ___ __________.
__________ ___ _________ _________ _______ ______ ___ ________ __________.
_________ ______ ____ _________ _____ ___ _________.
_______ __________ ___ ____ ______ __________ _________ ____.
_______ ___ ______ ________ _______ ____ ______ __________.
___ ___ _____ ______ __________ ______ _____ _____.
_______ ________ ___ ____ ________ _______ _________ __________ _______ _____ __________.
________ ___ ______ __________ ________ __________ ________ _____ _____ ____ ____ ___.
___ ____ ___ _____ ________ ____ _______ ___ _____ _______.
_______ __________ __________ __________ __________ __________ ______.
_______ __________ ___ _______ ___.
______ _____ ___ _____ _____.
_________ ___ __________ ___ ___ ____ ____ __________ ______ ________ _____.
___ ________ _____ _____ ____.
___ ____ __________ __________ _________ ________.
_______ ____ ____ ___ ___ ____ ____ ______ _______ ____ __________.
___ _______ _________ _________ _________ ____ __________ ____.
__________ ___ __________ ____ ______ _______ _______ _____ ___ _________.
___ ________ ______ _________ _________ _______ ____ _______ ___ _________ _________ _____.
_____ _____ ________ ____ _____.
__________ _____ _____ _______ _________ _____ ______ ____ ____.
________ ____ __________ ___ _______ ____ ______ _____ ___ ________ ______.
____ _________ _______ _____ _________ _________ ____ _________ ____.
______ _______ ________ ________ _______ ____ _______ ________ _______ ______.
_________ ____ ____ _______ _________ _______ _____ ____ __________ ____ _________.
______ _____ _________ _______ ___ __________ _________ _________.
_______ ________ _______ ___ _______ __________ _________.
____ __________ ________ ____ ___ ________ ____.
_____ _______ _________ ______ _____ __________.
________ ________ ________ ________ _______ ______ _____ ___.
__________ ________ ____ _________ _________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required