Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, below is my Oracle SQL statements for my assignment. When I try to run I get a few errors, Missing Comma Unique Constraint and

Hello, below is my Oracle SQL statements for my assignment. When I try to run I get a few errors, "Missing Comma" "Unique Constraint" and so forth. I have also attached a list from the assignment on what the statements should do. If someone could look over and correct the statements for it to run properly I would appreciate it.

--Drop Table if it already exists DROP TABLE Department;

-- Create Department relation schema CREATE TABLE Department ( deptName VARCHAR2(50) primary key, managerID NUMBER, CONSTRAINT deptManagerFK FOREIGN KEY(managerID) REFERENCES Employee(empID) ON DELETE SET NULL );

--Insert Data into Department Schema Insert into Department values('HR',666); Insert into Department (name) values ('RD'); Insert into Department values('SALES',222); Update Department SET managerID=888 where name='RD';

SELECT * from Department;

-- Create Employee relation schema CREATE TABLE Employee ( ID NUMBER PRIMARY KEY, empName VARCHAR2(50), salary NUMBER , deptname varchar2(50), CONSTRAINT empDeptFK FOREIGN KEY(deptname) REFERENCES Department(name) ON DELETE SET NULL );

ALTER TABLE Employee ADD CONSTRAINT chk_hr_salary CHECK (deptname != 'HR' OR salary >= 20000);

-- Insert Data into Employee Schema INSERT INTO Employee(ID NUMBER, empname, salary, deptname) VALUES('123', 'John', 56000, 'RD'); INSERT INTO Employee(ID NUMBER, empname, salary, deptname) VALUES(578, 'Robert', 37500, 'HR'); INSERT INTO Employee(ID NUMBER, empname, salary, deptname) VALUES(666, 'Jenny', 46000, 'HR'); INSERT INTO Employee(ID NUMBER, empname, salary, deptname) VALUES(222, 'Christ', 39000, 'SALES'); INSERT INTO Employee(ID NUMBER, empname, salary, deptname) VALUES(888, 'Bill', 50000, 'RD'); INSERT INTO Employee(ID NUMBER, empname, salary, deptname) VALUES(101, 'Susan', 67500, 'RD');

SELECT * from Employee;

--Deleting a record of Employee who is a Manager CREATE OR REPLACE TRIGGER del_employee_trigger BEFORE DELETE ON Employee FOR EACH ROW BEGIN IF :OLD.ID IN (SELECT managerID FROM Department) THEN UPDATE Department SET managerID = NULL WHERE managerID = :OLD.empID; END IF; END;

--Deleting record of a Department CREATE OR REPLACE TRIGGER del_department_trigger BEFORE DELETE ON Department FOR EACH ROW BEGIN UPDATE Employee SET dID = NULL WHERE ID = :OLD.ID; END;

--Changing the name of the Department CREATE OR REPLACE TRIGGER trg_update_dept AFTER UPDATE ON Department FOR EACH ROW BEGIN UPDATE Employee SET deptName = :NEW.deptName WHERE deptName = :OLD.deptName; END;

image text in transcribed

Use Oracle SQL to create a script file that declares relation schemas based on the following assumptions, and then inserts data records into the relations. a) Different departments have different names. b) A department may temporarily have no manager. c) Different employees may have the same name. An employee can be uniquely identified by the ID. d) People who work in the HR department always earn at least 20,000 dollars. e) When deleting a record of an employee who is a manager, the managerID field of the department the person works for should be set to null. f) When deleting a record of a department, the deptName field of all employees who work in that department should be set to null. g) When changing the name of a department in relation Department, values of attribute deptName in table Employee will also be changed accordingly. For example, if ' RD ' is changed to 'RESEARCH' in relation Department, all occurrences of ' RD in in table Employee will also to be automatically changed to 'RESEARCH'. Denartment Fmn 1 irno

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions