Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello below are my Oracle SQL statements for my assignment (Which I also attached below) If someone could look over it to ensure that it

Hello below are my Oracle SQL statements for my assignment (Which I also attached below) If someone could look over it to ensure that it runs properly I would appreciate it.

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

-- Create Department relation schema CREATE TABLE Department ( name VARCHAR(50) PRIMARY KEY, managerID INT );

SELECT * FROM Department;

-- Create Employee relation schema CREATE TABLE Employee ( ID INT PRIMARY KEY, name VARCHAR(50), deptName VARCHAR(50), salary DECIMAL(10,2), CONSTRAINT ck_salary CHECK ((deptName = 'HR' AND salary >= 20000) OR (deptName 'HR')) );

--Update Department so table can be created first ALTER TABLE Department ADD CONSTRAINT fk_managerID FOREIGN KEY (managerID) REFERENCES Employee(ID) ON DELETE SET NULL;

--Update Employee so table can be created first ALTER TABLE Employee ADD CONSTRAINT fk_deptName FOREIGN KEY (deptName) REFERENCES Department(name) ON DELETE SET NULL;

-- Insert data into Department INSERT INTO Department (name, managerID) VALUES ('HR', NULL), ('RD', 666), ('SALES', 222), ('888', NULL);

-- Insert data into Employee INSERT INTO Employee (ID, name, deptName, salary) VALUES (123, 'John', 'RD', 56000), (578, 'Robert', 'HR', 37500), (46000, 'Jenny', 'RD', 39000), (39000, 'Christ', 'HR', 50000), (50000, 'Bill', 'SALES', 67500), (101, 'Susan', 'RD', NULL);

SELECT * FROM Employee;

-- Add ON UPDATE CASCADE constraint to Department relation schema ALTER TABLE Department ADD CONSTRAINT fk_deptName_employee FOREIGN KEY (name) REFERENCES Employee(deptName) ON UPDATE CASCADE;

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_2

Step: 3

blur-text-image_3

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

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

Explain an application of K-means clustering.

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago