Question

In: Computer Science

Using SQL Developer ONLY! Lab 5 1. Create a lab report file (MS Word compatible) and...

Using SQL Developer ONLY!

Lab 5 1.

Create a lab report file (MS Word compatible) and name it as “IT4153_Lab 5_ Your D2L ID”.

a. Create two tables: Employee: empID (PK), empFname, empLname, deptID(FK) and Department: deptID(PK), deptName, chairID chairID is empID from Employee table

b. Insert at least 3 rows in the Department table and at least 6 rows in the Employee table.

c. Create trigger on update of chairID that enforces the following business rules • One employee can chair no more than one department. • Each department has exactly one chair.

Note: Check what happens with department when you delete it's chair from the table

Solutions

Expert Solution

create table Employee(empID NUMBER,
empFname VARCHAR2(20),
empLname VARCHAR2(20),
deptID NUMBER,
PRIMARY KEY (empID)
);
  
ALTER TABLE Employee
ADD FOREIGN KEY (deptID) REFERENCES Department(deptID);
  
  
create table Department(deptID NUMBER,
deptName VARCHAR2(20),
chairID NUMBER,
PRIMARY KEY (deptID));
  

ALTER TABLE Department
ADD FOREIGN KEY (chairID) REFERENCES Employee(empID);   
  
  
  
--b part
insert into Employee values (101,'John','Kennedy',10);
insert into Employee values (102,'Ram','Kumar',10);
insert into Employee values (103,'Shayam','Lal',12);
insert into Employee values (104,'Donald','Trump',12);
insert into Employee values (105,'NArendra','Modi',12);
insert into Employee values (106,'Jackie','Obama',10);


insert into Department values (10,'Economics',101);
insert into Department values (12,'Economics',102);
insert into Department values (15,'Economics',103);


--c.

CREATE OR REPLACE TRIGGER chairID_after_update
BEFORE UPDATE
ON Department
FOR EACH ROW

DECLARE
v_username varchar2(10);
v_count number;
v_sql varchar2(50);
BEGIN

select count(*) into v_count from Department where chairID = :new.chairID;
IF v_count = 0 then
v_sql := 'alter table set chairID ='+ :new.chairID;
execute immediate v_sql;
end if;

END;
/


Related Solutions

Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password TESTACCOUNT that grants the user the ability to: Select and modify any table. Connect to and have access to all resources. In SSMS
Using SQL Developer Question 1 Create a block to retrieve and display pledge and payment information...
Using SQL Developer Question 1 Create a block to retrieve and display pledge and payment information for a specific donor. For each pledge payment from the donor, display the pledge ID, pledge amount, number of monthly payments, payment date, and payment amount. The list should be sorted by pledge ID and then by payment date. For the first payment made for each pledge, display “first payment” on that output row. Question 2 Redo question 1, but use a different cursor...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
using C thank you Must submit as MS Word file with a screenshot of the 3...
using C thank you Must submit as MS Word file with a screenshot of the 3 outputs. Run your program 3 times. the output must be in a screenshot not typed for the each time you run the program. thank you Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will...
Design Activity #1—Project Proposal: In the designated project activity Word file, please create a written report...
Design Activity #1—Project Proposal: In the designated project activity Word file, please create a written report (single-spaced, minimum of 600 additional words, small paragraphs) that describes a new proposed product for a B2C or B2B app. Your report should include the following sections: Title of your project, Author name & date, Description of the intended product (the intended look and feel of the product (via a simple sketch), and how it will function for the user), Intended delivery platform (PC,...
For Assignment 2, submit a word or pdf file with the SQL queries along with screenshots...
For Assignment 2, submit a word or pdf file with the SQL queries along with screenshots of the outputs. (It is ok if the whole problem cannot be answered, if possible, I just would like an idea of how to begin, thanks in advance!) 9. Write a query to count the number of invoices. 10. Write a query to count the number of customers with a balance of more than $500. 11. Generate a listing of all purchases made by...
Answer the 3 problems below using company sql file Company pays 5% of the salary of...
Answer the 3 problems below using company sql file Company pays 5% of the salary of an employee as the 401k benefit. List the total amount of money that the company pays as 401k for all of its employees. Change the column name as total401k. Find the total hours that employees work on project ’ProductX’. List the first name, last name, department name, and salary of the female employee that has the highest salary. below is company.sql DROP DATABASE IF...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE:...
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least...
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least three rows in each table. For the On-Demand Streaming System, First, insert information for multiple users, at least three video items and insert the three different types of subscriptions (Basic, Advanced, Unlimited) into the database. Then insert at least three user subscriptions. Execute the queries and make sure they run correctly
Using Triggers (5 pts.) Execute the following SQL to create the customer_audit table in the premier...
Using Triggers (5 pts.) Execute the following SQL to create the customer_audit table in the premier schema. CREATE TABLE IF NOT EXISTS customer_audit ( customer_num CHAR(3) NOT NULL,   customer_name VARCHAR(35) NOT NULL, street VARCHAR(15), city VARCHAR(15), state CHAR(2), zip CHAR(5), credit_limit DECIMAL(8,2), date_changed DATETIME NOT NULL, changed_by VARCHAR(45) NOT NULL); Notice that the audit table does not have a primary key defined. Explain why this might be acceptable. Based on the current attributes in the customer_audit table, suggest a possible...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT