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...
Create a new SQL Developer SQL worksheet and create/run the following TWO (2) queries and save...
Create a new SQL Developer SQL worksheet and create/run the following TWO (2) queries and save your file as Comp2138LabTest1_JohnSmith100123456.sql (replace JohnSmith 100123456 with your name and student ID). Please place comment that includes your name and your student ID at the top of your script and number your queries using comments sections. Each query carries equal weight. A selection of the expected result set has been shown below for your convenience. Your output should match with this sample output....
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,...
Create a 300–400 word report outlining the following: What are the two types of file exists...
Create a 300–400 word report outlining the following: What are the two types of file exists on all computers? List the best practices for File Management.
Use the SQL Developer to create the four tables EMP, DEPT, PROJ, EMP_PROJ with the appropriate...
Use the SQL Developer to create the four tables EMP, DEPT, PROJ, EMP_PROJ with the appropriate constraints except FOREIGN KEY constraints. For filename, use CREATE.sql accordingly. Import data from the csv files to EMP, DEPT, and PROJ tables. Check that all data for EMP, DEPT, and PROJ tables has been imported. __________________________ employees.csv empNo,fname,lname,address,sex,salary,position,deptNo 1000,Steven,King,"731 Fondren, Houston, TX",M,30000,Programmer,60 1007,Diana,Lorentz,"638 Voss, Bellaire, TX",F,24000,Clerk,20 2002,Pat,Fay,"3321 Castle, Spring, TX",F,15000,Sales Representative,80 1760,Jonathan,Taylor,"561 Rice, Houston, TX",M,60000,Manager,20 1740,Ellen,Abel,"890 Stone, Houston, TX",F,65000,Manager,60 2060,William,Gietz,"450 Berry, Bellaire, TX",M,65000,Manager,80 2000,Jennifer,Whalen,"980...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT