Write a pl-sql and creating a trigger


Use Oracle SQL*PLUS to answer the following queries. It is recommended that you either use Notepad or similar (not Word) to initially create the queries.

A company keeps information on employees, their grades, the department they work in, the projects they work on and the time spent in hours on each project for a particular week. A project has a start date and also an end date is recorded on completion of the project. In addition information is held concerning customers - each project is sponsored by a particular customer although one customer may have several projects. Skills required for a particular project are recorded together with the skills that each employee possesses.
A Relational Database is to be set up for you to query. The schema and data files are in the Database folder (weeks 1-12) on OasisPlus. The tables in the database are shown below. The identifier attribute(s) are underlined, foreign keys are asterisked *.

Table Name              Attributes
Department             Dptno,Dname
Employee                Empno, Ename, Dptno*,Gradeno*,
Grade                     Gradeno,Gtitle,Salary
Project                    Projno, Ptitle, pstart, pfinish, Custno*,
Timesheet               Weekno,Empno*,Projno*,Hours
Customer                Custno, cname, location
Skill                        Skillno*,Sname
Skillproj                  Skillno*,Projno*
Empskill                  Empno*, Skillno*

It is essential that you draw an Entity-Relationship diagram (mapped to a relational database) showing the entities and relationships involved and use this when working out your code. Do not hand in this diagram– it is not assessed.

Further SQL

Study the Art College case above.

Use Oracle iSQL*PLUS to answer the following queries.  Please indicate which question a particular solution refers by using comments e.g. /* Question 1 Find names…*

1) List employees (number and name) who work in the Web Design department.

2) List the employees (by name) who have recorded time on projects which are sponsored by customer Cater Allan at any time.

3) List the employees (by employee name and department name) who have the skills required for current projects for customer Butterfield.

4) Give the name of all employees who work in the same department as Ivor (not including Ivor).

5) How much has project ‘Pegasus’ cost so far? You can assume that there are 1600 working hours in a year, i.e. the cost of employing someone for one hour on a project is 1/1600th of his/her annual salary.

6) What is the total cost of and hours worked by each department for each week. The output from this query should look something like:

DNAME                    WEEKNO TOTALHOURS  TOTALCOST
-------------------- ---------- ---------- -------------------------------
Accounts                      1                200           6425
Accounts                      2                120           3650

7) Which employees (by name), apart from Baz, have any skill that is required on a project which Baz has worked on? Use a self join to answer this question.

8)  Give the names of any employees who work (or have worked) on all the projects in the database.

Triggers and stored procedures

Don’t forget to type the command ‘set serveroutput on’ before executing the code in this section. If you are forced out of SQL*PLUS don’t forget to retype this command.

a) Write a PL/SQL block which includes a procedure get_customer which accepts a project title and returns the customer name and location for that project. The main block should call the procedure with project title Phoenix, and output the customer name and location.

b) Write a PL/SQL block, which displays all employees’ numbers, name and grade title with their salary decreased by 15%.

c) Create a trigger ‘checkprojects’ to enforce the constraint that employees can only work on a maximum of 5 projects in any week. The trigger fires whenever this is an insert to the timesheet table and outputs an error message indicating the employee’s number and a suitable message whenever the total number of projects for a particular week exceeds 5. (Ignore the possibility that some rows in the given table may already violate this constraint.).

Use the following examples of insert to the timesheet table; showing the update when successful and unsuccessful (i.e. the constraint is violated).

INSERT INTO Timesheet VALUES (1,1,5,5);

INSERT INTO Timesheet VALUES (1,1,6,17);

For testing purposes the following commands (which set the database back to its original state) might be useful:

delete from Timesheet where weekno=1 and empno=1 and projno=5;

delete from Timesheet where weekno=1 and empno=1 and projno=6;

Request for Solution File

Ask an Expert for Answer!!
PL-SQL Programming: Write a pl-sql and creating a trigger
Reference No:- TGS0601

Expected delivery within 24 Hours