Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Database System Concepts class (text book using is \' database system co

ID: 3602730 • Letter: T

Question

This is Database System Concepts class (text book using is 'database system concepts (6th edition) by silberschatz korth and sudarshan')

Solve question 1 using standard SQL. Solve question 2 using either standard SQL or Oracle. Please write clearly and explain your solution where needed.

1. Consider the database given in Figure 4.12, page 155 of the text. Create an SQL assertion that ensures that every name that appears in the relation address appears in either salaried_worker or hourly_worker, but not necessarily in both.

2. Suppose you are given a relation emp(empid, dept, salary) and wish to maintain a materialized view deptsalary(dept, totalsalary) which stores the total salary for all employees of each department. Suppose the system does not support materialized views but supports triggers. Write an SQL or Oracle trigger on insert on emp to keep the relation deptsalary up to date. Do not worry about deletes or updates. You can assume that there is already a tuple for each department in deptsalary so you do not need to worry about new deparments. (Note: if you solve this question using Oracle, do not create a view for deptsalary, just create a table for it.)

Explanation / Answer

SOLUTION

1)

create assertion worker check (not exists ( select name from Salaried_worker = select name from Hourly_worker));

2)

create or replace trigger Total_SalaryUpdate
after insert on emp

for each row
declare
dept_exists pls_integer :=0;
begin
select count(1)
into dept_exists
from deptsalary
where dept = :new.dept;

if dept_exists > 0 then
UPDATE deptsalary
SET totalsalary = totalsalary +:new.SALARY
where dept = :new.dept;
else
INSERT INTO deptsalary VALUES (:new.DEPT,:new.SALARY);
end if;
end;

ALL QUESTIONS ARE SOLVED
THANK YOU

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote