CPA LaboratoryActivity001
CPA LaboratoryActivity001
Direction: Copy and paste the PL/SQL code on the space provided after each questions ad explain each number
with question that requires you to answer in essay form.
1. Create a table name as: EMPLOYEE_RECORD with the following column as shown below:
ID FIRSTNAME LASTNAME EMAIL JOB_ID SALARY DEPT_ID
Number(6) Varchar(10) Varchar(10) Varchar(15) Varchar15 Number(6) Number(6)
PK NOT NULL
CREATE TABLE EMPLOYEE_RECORD
(ID NUMBER(6) PRIMARY KEY,
FIRSTNAME VARCHAR(10) NOT NULL,
LASTNAME VARCHAR(10),
EMAIL VARCHAR(15),
JOB_ID VARCHAR(15),
SALARY NUMBER(6),
DEPT_ID NUMBER(6));
3. Add new column name as ADDRESS data type char size 20.
ALTER TABLE EMPLOYEE_RECORD
ADD ADDRESS VARCHAR(20);
4. After you add a new column address view now the table? What happen to the addresses of all old
employees? Explain the reason why?
SELECT * FROM EMPLOYEE_RECORD;
The address of old employees is blank because the ‘ADDRESS’ attribute was not present
when the previous employee records were inserted into the ‘EMPLOYEE_RECORD’ table.
Is inserting a new record in No.5 is possible? Why and why not? Explain the reason why?
The insert operation on No.5 is possible because the number of inserted values
matches the number of attributes in the ‘EMPLOYEE_RECORD’ table.
Is inserting a new record in No.6 is possible? Why and why not? Explain the reason why?
The insert operation in No.6 is not possible because there is an existing entry
with the ID 105 in the ‘EMPLOYEE_RECORD’ table. A primary key constraint prevents
duplicate entries in a table.
Is inserting a new record in No. 8 is possible? If not perform some modification on table structure in
order to insert the record of Ms. Valencia.
The insert operation in No.8 is not possible because the ‘ADDRESS’ attribute’s size
is 20 while the inserted ‘ADDRESS’ in the insert query has a size of 34. The table
must be altered in order to insert the said record.
ALTER TABLE EMPLOYEE_RECORD
MODIFY ADDRESS VARCHAR(40);
Note: For succeeding activity: make sure to view you table and study its content.
8. All employees that having a salary of 5800 should be assigned in one dept_id 90, update their
departments to 90.
UPDATE EMPLOYEE_RECORD
SET DEPT_ID = 90
WHERE SALARY = 5800;
9. Trina got married, after her leave Ms. Trina ask you to update her record in the database from RAJS to
DE LEON.
UPDATE EMPLOYEE_RECORD
SET LASTNAME = 'DE LEON'
WHERE LASTNAME = 'Rajs';
10. After serving the company for three year Randal got promoted as the newest ad_pres and with a new
salary of 250000. Update his record using one SQL only.
UPDATE EMPLOYEE_RECORD
SET JOB_ID = 'Ad_pres', SALARY = 250000
WHERE FIRSTNAME = 'Randal';
11. Since Mr. Randal replace the position of Mr. Steven, delete the record of Mr. Steven since he is no
longer connected to the company.
DELETE FROM EMPLOYEE_RECORD
WHERE FIRSTNAME = 'Steven';
12. All employees are given an additional 2% increase in their salaries. Create an SQL statement that would
change the employees’ salaries with additional 10%. Note: Use rows with the same values in order to
limit the number of query to be use.
UPDATE EMPLOYEE_RECORD SET SALARY = 17000+(17000*0.12) WHERE SALARY = 17000;
UPDATE EMPLOYEE_RECORD SET SALARY = 9000+(9000*0.12) WHERE SALARY = 9000;
UPDATE EMPLOYEE_RECORD SET SALARY = 6000+(6000*0.12) WHERE SALARY = 6000;
UPDATE EMPLOYEE_RECORD SET SALARY = 5800+(5800*0.12) WHERE SALARY = 5800;
UPDATE EMPLOYEE_RECORD SET SALARY = 250000+(250000*0.12) WHERE SALARY = 250000;
UPDATE EMPLOYEE_RECORD SET SALARY = 2600+(2600*0.12) WHERE SALARY = 2600;
UPDATE EMPLOYEE_RECORD SET SALARY = 50000+(50000*0.12) WHERE SALARY = 50000;
13. Email address is not being use, and save space you have to delete the said column.
ALTER TABLE EMPLOYEE_RECORD
DROP COLUMN EMAIL;
14. Select the table now and draw the final output after you perform the DDL and DML statements.
SELECT * FROM EMPLOYEE_RECORD;
15. What will happen if the accidentally type DELETE * FROM EMPLOYEES without issuing WHERE
condition?
The query ‘DELETE * FROM EMPLOYEES’ will return an error because the table ‘EMPLOYEES’
does not exist in the database. The said query will not affect any data in the
database.