Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I need help answering these questions on the table; if you could run both scrips on apex that will help get the answers; here

Hello I need help answering these questions on the table; if you could run both scrips on apex that will help get the answers; here is the CREATE scrip

/*---------------------------------------------------------------------------------------------------

COURSE: DBMS 130: Data Management using SQL (Structured Query Language) SCRIPT: M01_HOL_Script CREATE PURPOSE: Execute script for creating database structures required to complete M01 Hands-On Lab and subsequent Hands On Labs 2-8.

---------------------------------------------------------------------------------------------------*/

-- -------------------------------------------------------------------------------------------------- -- DROP DATABASE OBJECTS AND ASSOCIATED CONSTRAINTS -- --------------------------------------------------------------------------------------------------

DROP TABLE HOL_REGIONS CASCADE CONSTRAINTS; DROP TABLE HOL_COUNTRIES CASCADE CONSTRAINTS; DROP TABLE HOL_LOCATIONS CASCADE CONSTRAINTS; DROP TABLE HOL_DEPARTMENTS CASCADE CONSTRAINTS; DROP TABLE HOL_EMPLOYEES CASCADE CONSTRAINTS; DROP TABLE HOL_JOB_HISTORY CASCADE CONSTRAINTS; DROP TABLE HOL_JOBS CASCADE CONSTRAINTS;

DROP VIEW HOL_EMP_DETAILS_VIEW;

DROP SEQUENCE HOL_DEPARTMENTS_SEQ; DROP SEQUENCE HOL_EMPLOYEES_SEQ; DROP SEQUENCE HOL_LOCATIONS_SEQ;

-- -------------------------------------------------------------------------------------------------- -- CREATE TABLES -- --------------------------------------------------------------------------------------------------

-- CREATE REGIONS TABLE CREATE TABLE HOL_REGIONS ( REGION_ID INTEGER ,REGION_NAME VARCHAR2(250) ,CONSTRAINT PK_REG_ID PRIMARY KEY (REGION_ID) USING INDEX ENABLE );

-- CREATE COUNTRIES TABLE CREATE TABLE HOL_COUNTRIES ( COUNTRY_ID CHAR(2) ,COUNTRY_NAME VARCHAR2(250) ,REGION_ID INTEGER ,CONSTRAINT PK_COUNTRY_C_ID PRIMARY KEY (COUNTRY_ID) ENABLE );

-- ADD CONSTRAINTS TO COUNTRIES TABLE ALTER TABLE HOL_COUNTRIES ADD CONSTRAINT FK_COUNTR_REG FOREIGN KEY (REGION_ID) REFERENCES HOL_REGIONS (REGION_ID) ENABLE;

-- CREATE LOCATIONS TABLE CREATE TABLE HOL_LOCATIONS ( LOCATION_ID INTEGER ,STREET VARCHAR2(250) ,CITY VARCHAR2(250) ,STATE_PROVINCE CHAR(2) ,POSTAL_CODE VARCHAR2(50) ,COUNTRY_ID CHAR(2) ,CONSTRAINT PK_LOC_ID PRIMARY KEY (LOCATION_ID) USING INDEX ENABLE );

-- ADD CONSTRAINTS TO LOCATIONS TABLE ALTER TABLE HOL_LOCATIONS ADD CONSTRAINT FK_LOC_C_ID FOREIGN KEY (COUNTRY_ID) REFERENCES HOL_COUNTRIES (COUNTRY_ID) ENABLE; CREATE INDEX IX_LOC_CITY ON HOL_LOCATIONS (CITY); CREATE INDEX IX_LOC_COUNTRY ON HOL_LOCATIONS (COUNTRY_ID); CREATE INDEX IX_LOC_STATE_PROVINCE ON HOL_LOCATIONS (STATE_PROVINCE);

-- CREATE JOBS TABLE CREATE TABLE HOL_JOBS ( JOB_ID INTEGER ,JOB_TITLE VARCHAR2(250) CONSTRAINT NN_JOB_TITLE NOT NULL ENABLE ,MIN_SALARY NUMBER(12,2) ,MAX_SALARY NUMBER(12,2) ,CONSTRAINT PK_JOBS PRIMARY KEY (JOB_ID) USING INDEX ENABLE );

-- CREATE EMPLOYEES TABLE CREATE TABLE HOL_EMPLOYEES ( EMPLOYEE_ID INTEGER ,FIRST_NAME VARCHAR2(250) ,MIDDLE_NAME VARCHAR2(250) ,LAST_NAME VARCHAR2(250) CONSTRAINT NN_EMP_LAST_NAME NOT NULL ENABLE ,EMAIL VARCHAR2(250) ,PHONE VARCHAR2(50) ,HIRE_DATE DATE CONSTRAINT NN_EMP_HIRE_DATE NOT NULL ENABLE ,CURRENT_SALARY NUMBER(12,2) ,COMMISSION_PCT NUMBER(2,2) ,BONUS NUMBER(12,2) ,JOB_ID INTEGER ,MANAGER_ID INTEGER ,DEPARTMENT_ID INTEGER ,CONSTRAINT CK_EMP_SALARY_MIN CHECK (CURRENT_SALARY > 0) ENABLE ,CONSTRAINT PK_EMPLOYEES PRIMARY KEY (EMPLOYEE_ID) USING INDEX ENABLE ,CONSTRAINT UK_EMP_EMAIL UNIQUE (EMAIL) USING INDEX ENABLE ); -- ADD CONSTRAINTS TO EMPLOYEES TABLE ALTER TABLE HOL_EMPLOYEES ADD CONSTRAINT FK_EMP_JOB FOREIGN KEY (JOB_ID) REFERENCES HOL_JOBS (JOB_ID) ENABLE; ALTER TABLE HOL_EMPLOYEES ADD CONSTRAINT FK_EMP_MGR FOREIGN KEY (MANAGER_ID) REFERENCES HOL_EMPLOYEES (EMPLOYEE_ID) ENABLE; CREATE INDEX IX_EMP_DEPT ON HOL_EMPLOYEES (DEPARTMENT_ID); CREATE INDEX IX_EMP_JOB ON HOL_EMPLOYEES (JOB_ID); CREATE INDEX IX_EMP_MGR ON HOL_EMPLOYEES (MANAGER_ID); CREATE INDEX IX_EMP_NAM ON HOL_EMPLOYEES (LAST_NAME, FIRST_NAME);

-- CREATE DEPARTMENTS TABLE CREATE TABLE HOL_DEPARTMENTS ( DEPARTMENT_ID INTEGER ,DEPARTMENT_NAME VARCHAR2(250) ,MANAGER_ID INTEGER ,LOCATION_ID INTEGER ,CONSTRAINT PK_DEPT PRIMARY KEY (DEPARTMENT_ID) USING INDEX ENABLE ); -- ADD CONSTRAINTS TO EMPLOYEES, DEPARTMENTS TABLES ALTER TABLE HOL_EMPLOYEES ADD CONSTRAINT FK_EMP_DEPT FOREIGN KEY (DEPARTMENT_ID) REFERENCES HOL_DEPARTMENTS (DEPARTMENT_ID) ENABLE; ALTER TABLE HOL_DEPARTMENTS ADD CONSTRAINT FK_DEPT_MGR FOREIGN KEY (MANAGER_ID) REFERENCES HOL_EMPLOYEES (EMPLOYEE_ID) DISABLE; ALTER TABLE HOL_DEPARTMENTS ADD CONSTRAINT FK_DEPT_LOC FOREIGN KEY (LOCATION_ID) REFERENCES HOL_LOCATIONS (LOCATION_ID) ENABLE; CREATE INDEX IX_DEPT_LOCATION ON HOL_DEPARTMENTS (LOCATION_ID);

-- CREATE JOB_HISTORY TABLE CREATE TABLE HOL_JOB_HISTORY ( JOB_HISTORY_ID INTEGER GENERATED ALWAYS AS IDENTITY ,EMPLOYEE_ID INTEGER CONSTRAINT NN_JOB_HIST_EMP NOT NULL ENABLE ,START_DATE DATE CONSTRAINT NN_JOB_HIST_START_DATE NOT NULL ENABLE ,END_DATE DATE CONSTRAINT NN_JOB_HIST_END_DATE NOT NULL ENABLE ,JOB_ID INTEGER CONSTRAINT NN_JOB_HIST_JOB NOT NULL ENABLE ,DEPARTMENT_ID NUMBER(4,0) ,CONSTRAINT CK_JOB_HIST_DATE_INTERVAL CHECK (end_date > start_date) ENABLE ,CONSTRAINT PK_JOB_HISTORY PRIMARY KEY (EMPLOYEE_ID, START_DATE) USING INDEX ENABLE );

-- ADD FOREIGN KEY CONSTRAINTS TO EMPLOYEES TABLE ALTER TABLE HOL_JOB_HISTORY ADD CONSTRAINT FK_JOB_HIST_DEPT FOREIGN KEY (DEPARTMENT_ID) REFERENCES HOL_DEPARTMENTS (DEPARTMENT_ID) ENABLE;

-- the folLowing FK constraint is disabled as table -- contains historical data for employees that are not in the current employees table --ALTER TABLE JOB_HISTORY ADD CONSTRAINT FK_JOB_HIST_EMP FOREIGN KEY (EMPLOYEE_ID) -- REFERENCES EMPLOYEES (EMPLOYEE_ID) DISABLE;

ALTER TABLE HOL_JOB_HISTORY ADD CONSTRAINT FK_JOB_HIST_JOB FOREIGN KEY (JOB_ID) REFERENCES HOL_JOBS (JOB_ID) ENABLE; CREATE INDEX IX_JOB_HIST_DEPT ON HOL_JOB_HISTORY (DEPARTMENT_ID); CREATE INDEX IX_JOB_HIST_EMP ON HOL_JOB_HISTORY (EMPLOYEE_ID); CREATE INDEX IX_JOB_HIST_JOB ON HOL_JOB_HISTORY (JOB_ID);

-- -------------------------------------------------------------------------------------------------- -- ENABLE CONSTRAINTS -- --------------------------------------------------------------------------------------------------

-- ENABLE FK_DPT_MGR CONSTRAINT ALTER TABLE HOL_DEPARTMENTS ENABLE CONSTRAINT FK_DEPT_MGR;

-- -------------------------------------------------------------------------------------------------- -- CREATE VIEW -- --------------------------------------------------------------------------------------------------

-- CREATE EMP_DETAILS_VIEW VIEW CREATE OR REPLACE FORCE VIEW HOL_EMP_DETAILS_VIEW (EMPLOYEE_ID, JOB_TITLE, MANAGER_ID, DEPARTMENT_NAME, FIRST_NAME, LAST_NAME, SALARY, COMMISSION_PCT) AS SELECT E.EMPLOYEE_ID ,J.JOB_TITLE ,E.MANAGER_ID ,D.DEPARTMENT_NAME ,E.FIRST_NAME ,E.LAST_NAME ,E.CURRENT_SALARY ,E.COMMISSION_PCT FROM HOL_EMPLOYEES E INNER JOIN HOL_DEPARTMENTS D ON E.DEPARTMENT_ID = D.DEPARTMENT_ID INNER JOIN HOL_JOBS J ON J.JOB_ID = E.JOB_ID WITH READ ONLY ; -- -------------------------------------------------------------------------------------------------- -- CREATE SEQUENCES -- --------------------------------------------------------------------------------------------------

-- Create sequence for DEPARTMENTS PK CREATE SEQUENCE HOL_DEPARTMENTS_SEQ MINVALUE 1 MAXVALUE 9990 INCREMENT BY 10 START WITH 280 NOCACHE NOORDER NOCYCLE ;

-- Create sequence for EMPLOYEES PK CREATE SEQUENCE HOL_EMPLOYEES_SEQ MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 207 NOCACHE NOORDER NOCYCLE ;

--Create sequence for locations PK CREATE SEQUENCE "HOL_LOCATIONS_SEQ" MINVALUE 1 MAXVALUE 9900 INCREMENT BY 100 START WITH 3300 NOCACHE NOORDER NOCYCLE ;

image text in transcribedimage text in transcribed

Follow the steps below to learn how to navigate the database environment you will use for all the hands-on lab assignments in the course. A. Environment Login and Setup ( 30 points) 1. Download these two script files to your device. a. M01_001_HOL_Script_CREATE_yourInitials.sql b. M01_002_HOL_Script_INSERT_UPDATE_yourlnitials.sql 2. Rename these files by replacing yourlnitials with your own initials. 3. Log into APEX. a. Use our class workspace and your IVY Tech email as user ID. b. The initial password will be Spring2023. You will be required to change this password the first time you log into APEX. 4. Upload the two renamed files from your device into your APEX schema using the APEX Scripts tool. 5. Run the first script file until you receive no errors. a. This may take 2-3 runs. b. If you still have errors after run 3 , please let me know. 6. After the first script file runs successfully, run the second script file until you receive no errors. a. This may take 2-3 runs. b. If you still have errors after run 3 , please let me know. 7. I will grade this part of the assignment directly in APEX. 8. Then, complete the following questions and submit these for grading. 19. Which table has unique constraint? On which column is the unique constraint? Use format Jable. Name. Columnan Name. 20. How does this constraint impact the data that can be entered into this column? 21. Which table and column does the foreign key constraint with the name FK_EMP_DEPT reference that is contained in the EMPLOYEES table? Use format Table Name.Columan Name. 22. Which table and column does the foreign key constraint with the name FK_EMP_JOB reference that is contained in the EMPLOYEES table? Use format Table Name Columnon Name. 23. Which table and column does the foreign key constraint with the name FK_JOB_HIST_DEPT reference that is contained in the JOB_HISTORY table? Use format Table Name. Columnoname. 24. Which table and column does the foreign key constraint with the name FK_EMP_MGR reference that is contained in the EMPLOYEES table? Use format Table Name Columononame. 25. Why is the foreign key constraint necessary? That is, what is the purpose of foreign keys? Answer these miscellaneous questions. 26. How many countries are in the database? 27. What departments are located at 2004 Charade Rd, Seattle, WA 98199

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

Draw a schematic diagram of I.C. engines and name the parts.

Answered: 1 week ago

Question

OUTCOME 5 Discuss sexual harassment as an employment equity issue.

Answered: 1 week ago