DBMS LAB ASSIGNMENT 3

LAB EXERCISES

LAB 3:

Joins

  1. Display all employee name and their department name, in department name order.

  2. Display all employee names, department number and name.

  3. Display the name, location and department of employees whose salary is more than 1500 a month.

  4. Produce a list showing employees salary grades.

  5. Show only employees on Grade 3.

  6. Show, all employees in dallas.

  7. List the employee name, job, salary, grade and department name for everyone in the company except clerks. Sort on salary, displaying the highest salary first.

  8. List the following details for employees who earn $36000 a year or who are clerks.

  9. Display the department that has no employees.

  10. List all employees by name and number along with their managers name and number.

  11. Modify solution to question 10 to display KING who has no manager.

  12. Find the job that was filled in the first half of 1993, and the same job that waf filled during the same period in 1994.

  13. Find all employees who joined the company before their manager.

  14. Find another query method for Question 9.

  15. Find employee(s) who earn the highest salary in each job type. Sort in descending order of salary.

  16. Find the employees who earn the minimum salary for their job. Display the result in ascending order of salary.

  17. Find the most recently hired employees in each department. Order by hire_date.

  18. Show the following details for any employee who earns a salary greater than the average for their department. Sort in department number order.

  19. List all the departments where there are no employees.(Using , a subquery this time)

  20. Display the following information for the department with HIGHEST annual remuneration bill.

  21. Who are the top 3 earners in the company? Display their names and salary.

  22. In which year did the most people join the company? Display the year and number of employees.

  23. Modify question 18 to also display the average salary figure for the department.

  24. Write a query to display an ‘*’against the row of the most recently hired employee. Display Ename,HIREDATE AND COLUMN(MAXDATE) SHOWING ‘*’.

  25. CREATE A TABLE CALLED projects, with columns as specified below. In addition, define PROJID as the primary key column, and ensure that P_END_DATE dates are not earlier than P_START_DATES dates.

Column Name data type Size

PROJID NUMBER 4

P_DESC VARCHAR2 20

P_START_DATE DATE

P_END_DATE DATE

BUDGET_AMOUNT NUMBER 7,2

MAX_NO_STAFF NUMBER 2

  1. CREATE ANOTHER table, ASSIGNMENTS. Define its PROJID column as a forign keywhich

Column name data type Size

PROJID NUMBER 4

EMP NO NUMBER 4

A_START_DATE DATE

A_END_DATE DATE

BILL_RATE NUMBER 4,2

ASSIGN TYPE NUMBER 2

  1. Add a LONG column called comments to your PROJECTS TABLE. Also, add a NUMBER column called HOURS to the ASSIGNMENTS table.

  2. Use the USER-OBJECTS dictionary view to list the objects owned by your Oracle account. How many objects do you own?

  3. Now define a constraint on the ASSIGNMENTS table to ensure unique combinations of Project ID and Employee number.

  4. Requery the USER_OBJECTS view; do you now own any further objects?

  5. Look in the Data Dictionary for information about constraints on your tables(you can use the view USER CONSTRAINTS

  6. Use tha ALL-TABLES dictionary view to find the owners and names of tables you can access where the table’s name includes the characters ‘EMP’.

  7. Insert into the PROJECTS table the following rows:

PROJID

P_DESC WRITE C030 COURSE PROOF RAED NOTES

P_START_DATE 02-JAN-88 01-JAN-89

P_END_DATE 07-JAN-88 01-JAN-89

BUDGET_AMOUNT 500 600

MAX_NO_STAFF