LA-2 (Constraints, Operators and Functions) Exercise: I Aim: To know how the constraints are used to make table is consistent. Table Name: Employee Attribute First Name Mid Name Last Name SSN Number Birthday Address Sex Salary Supervisor SSN Data Type Varchar (15) Char(2) Varchar (15) Char (9) Date Varchar (50) Char(1) Number (7) Char (9) Department number Number(5) Constraint Not Null Not Null Primary Key Sex In (M,F,m,f) Default 800 Foreign Key Employee (SSN) on delete set null Foreign key to department number of department table on delete cascade Table Name : Department Attribute Department Name Department number Manager SSN Data type Varchar(15) INT(5) Char (9) Manage start date Date Constraint Not Null Primary key Foreign key-Employee (SSN) on delete set null Table Name : Dept_locations Attribute Department Number Number(5) Data type Department Location Varchar (15) Constraint Department (dep no) onDelete Cascade Table Name: Project Attribute Project Name Project number Project Location Department Number Data type Varchar2(15) Number(5) Varchar2(50) Number(5) Constraint Not Null Primary key Foreign Key –Department (dep no ) on delete set null Table Name: Works_On The combination of Employee SSN and Project Number must be a Primary Key Attribute Employee SSN Data type Char (9) Project number INT(5) Hours Decimal (3,1) Constraint Foreign Key Employee (SSN) on delete cascade Foreign Key project ( Pnumber ) on delete cascade Not null Name: Dependent The combination of Employee SSN and Dependent Name must be a Primary Key. Attribute Employee Datatype Char (9) Dependent Name Sex Birthday Relationship Varchar(15) Char(1) Date Varchar(8) Data for table - Dept_Locations Dep No 1 1 2 2 3 4 4 5 5 D Location Houston Chicago New York San Francisco Salt Lake City Stafford Bellaire Sugarland Houston Constraint Foreign Key- Employee (SSN) on Delete Cascade Check Sex in (M,F,m,f) Data for Table - Works_On ESSN 123456789 123456789 666884444 453453453 453453453 333445555 333445555 333445555 333445555 999887777 999887777 543216789 554433221 Pno 3388 1945 3388 77 22 77 6688 43 22 1 12 22 1945 Hours 32.5 7.5 40.0 20.0 20.0 10.0 10.0 35.0 28.5 11.5 13.0 17.0 21.5 Data for Table - Dependent ESSN 333445555 333445555 333445555 987654321 123456789 123456789 Dependent_name Alice Theodore Joy Abner Alice Elizabeth Sex F M F M F F Bdate 05-Apr-76 25-Oct-73 03-May-48 29-Feb-32 31-Dec-78 05-may-57 Relationship Daughter Son Spouse Spouse Daughter Spouse Execute the following Query on the Db to display and discuss the integrity constraints violated by any of the following operations 1. Insert ('Robert', 'F', 'Scott', '943775543', '21-JUN-42', '2365 Newcastle Rd, Bellaire, TX', M, 58000, '888665555', 1 ) into EMPLOYEE. 2. Insert ( '677678989', null, '40.0' ) into WORKS_ON. 3. Insert ( '453453453', 'John', M, '12-DEC-60', 'SPOUSE' ) into DEPENDENT 4. Delete the WORKS_ON tuples with ESSN= '333445555'. 5. Modify the MGRSSN and MGRSTARTDATE of the DEPARTMENT tuple withDNUMBER=5 to '123456789' and '01-OCT-88', respectively. Alter the tables to 1. Add Foreign Keys using Alter Table [if not done earlier]. 2. Drop Foreign key defined on SuperSSN and add it using Alter table command. 3. Make name of Project as Unique and sex of employee as not null. 4. Make Address as a new type containing door no, street, city, State, Continent. 5. Make salary of employee to accept real values. Exercise:2 (based on operators, constraints and functions) https://blog.51cto.com/u_15060458/3857077 1. Display the dept information from department table 2. Display the details of all employee 3. display the name and job for all employee 4. display name and salary for all employee 5. display employee number and total salary for each employee 6. display employee name and anual salary for all employee 7. display the names of all employee who are working in department number 10 8. display the names of all employee working as clerks and drawing a salary more than 3000 9. display employee number and names for employee who earns commission 10. display names of employee who do not earn any commission 11. display the names of employee who are working as clerk, salseman or analyyst and drawimg a salary more than 3000 12. display the names of employee who are working in company for the past 5 years 13. display the list of employee who have joines the company before 30 june 90 or after 31 dec 90 14. display the names of employee working in department number 10 or 20 0r 40 or employee working as clerks, salseman or analyst 15. display names of employee whose name starts with alphabet S 16. display names of employee whose name ends with alphabet S 17. display the names of employee whose names have second alphabet A in their names 18. display the names of employee whose name is exactly five charactere in length 19. display the total number of employee working in the company 20. display the total salary being paid to all employee 21. display the maximum salary from emp table 22. display minimum salary from emp table 23. display the average salary from emp table 24. display the maximum salary being paid to clerk 25. display the maximum salary being paid in dept no 20 26. display the min salary being paid to any salseman 27. display the average salary drawn by manager 28. display the names of employee in order of salary i.e the name of the employee earning lowest salary should appear first 29. display the names of employees in descending order of salary 30. display the details from emp table in order of emp name 31. display empno ename deptno and sal. sort the output first based on name and within name by deptno and within deptno by sal 32. display the name of the employee along with their annual salary (sal*12) the name of the employee earning highest annual salary should appear first 33. display name, sal, hra, pf, da, total sal for each employee. the output shouldbe in the order oftotal sal, hra 15% of sal,da 10% of sal, pf 5%of sal total salary will be (sal*hra*da)-pf 34. display dept number and total number of employees within each group 35. display the various jobs and total number of employee with each job group 36. display department number and total salary for each department 37. display department number and maximum salary for each depatrment 38. display the various jobs and total salary for each job 39. display each job along with minimum sal being paid in each job group 40. display the department numbers with more than three employee in each dept 41. display the various jobs along with total sal for each of the jobswhere total sal is greater than 40000 41. display the various jobs along with total number of employee in each job. the outputshould contain only those jobs with more than three employee 42. display the name of emp who earns highest sal 43. display the employee number and name of employee working as cleark and earning highest salary among clerks 44. display the names of clearkwho earn salary more than that of james of that of sal lesser than that of scott 45. display names of employees who earns a sal more than that of james or that of salarygreater than that of scott 46. select ename, dname, job, empno, hiredate, loc from emp, dept where emp.deptno = dept.deptno order by ename Exercise: 3 Group Functions 1. How many different departments are there in the ‘employee’ table 2. For each department display the minimum and maximum employee salaries 3. Print the average annual salary. 4. Count the number of employees over 30 age. 5. Print the Department name and average salary of each department. 6. Display the department name which contains more than 30 employees. 7. Calculate the average salary of employees by department and age 8. Count separately the number of employees in the finance and research department. 9. List out the employees based on their seniority. 10. List out the employees who works in ‘manufacture’ department group by first name