Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Course Code Type Course Code Here

Database Management System


Description
1
College / Department:
Quiz No. 001
Online Education
Laboratory Exercise Page 1 of 1

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 LASTNAM EMAIL JOB_ID SALARY DEPT_ID
E
Number(6) Varchar(10) Varchar(10) Varchar(15) Varchar15 Number(6) Number(6)
PK NOT NULL
CREATE table "EMPLOYEE_RECORD2" (
"ID" NUMBER(6),
"FIRSTNAME" VARCHAR2(10) NOT NULL,
"LASTNAME" VARCHAR2(10),
"EMAIL" VARCHAR2(15),
"JOB_ID" VARCHAR2(15),
"SALARY" NUMBER(6),
"DEPT_ID" NUMBER(6),
constraint "EMPLOYEE_RECORD2_PK" primary key ("ID")
)
/
2. Insert the following Data as shown in the table below:
ID FIRSTNAME LASTNAM EMAIL JOB_ID SALARY DEPT_ID
E
100 Steven King Sking Ad_pres 240000 10
101 Nena Kochar Nkochar Ad_vp 17000 20
102 Lex De haan Ldehaan Ad_vp 17000 50
103 Alexander Hunold Ahunold It_prog 9000 60
104 Bruce Ernst Bernst It_prog 6000 80
107 Diana Lorentz Dlorentz St_man 5800 90
124 Kevin Mourgos Kmourgos St_clerk 5800 110
141 Trina Rajs Trajs St_clerk 5800 190
142 Curtis Davias Cdavias St_clerk 5800 191
143 Randal Matos Rmatos St_man 4200 195

Tabl Dat Indexe Mode Constraint Grant UI Trigger Dependencie


e a s l s s StatisticsDefaults s s SQL
CREATE TABLE "EMPLOYEE_RECORD2"
( "ID" NUMBER(6,0),
"FIRSTNAME" VARCHAR2(10) NOT NULL ENABLE,
"LASTNAME" VARCHAR2(10),
"EMAIL" VARCHAR2(15),
"JOB_ID" VARCHAR2(15),
"SALARY" NUMBER(6,0),
"DEPT_ID" NUMBER(6,0),
CONSTRAINT "EMPLOYEE_RECORD2_PK" PRIMARY KEY ("ID") ENABLE
) ;

3. Add new column name as ADDRESS data type char size 20.
alter table "EMPLOYEE_RECORD2" add
("ADDRESS" CHAR(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? After adding a new column, which is the address, the addresses of
all old employees were blank because in the old table, there were no address in the data of the
employees.
Tabl Dat Indexe Mode Constraint Grant UI Trigger Dependencie
e a s l s s StatisticsDefaults s s SQL
CREATE TABLE "EMPLOYEE_RECORD2"
( "ID" NUMBER(6,0),
"FIRSTNAME" VARCHAR2(10) NOT NULL ENABLE,
"LASTNAME" VARCHAR2(10),
"EMAIL" VARCHAR2(15),
"JOB_ID" VARCHAR2(15),
"SALARY" NUMBER(6,0),
"DEPT_ID" NUMBER(6,0),
"ADDRESS" CHAR(20),
CONSTRAINT "EMPLOYEE_RECORD2_PK" PRIMARY KEY ("ID") ENABLE
) ;

5. Add new record as shown below:


10 JUL SORIAN MSORIANO TEACHER 2600 8 BRGY.PAMBUAN GAPAN
5 Y O 0
CREATE TABLE "EMPLOYEE_RECORD2"
( "ID" NUMBER(6,0),
"FIRSTNAME" VARCHAR2(10) NOT NULL ENABLE,
"LASTNAME" VARCHAR2(10),
"EMAIL" VARCHAR2(15),
"JOB_ID" VARCHAR2(15),
"SALARY" NUMBER(6,0),
"DEPT_ID" NUMBER(6,0),
"ADDRESS" CHAR(20),
CONSTRAINT "EMPLOYEE_RECORD2_PK" PRIMARY KEY ("ID") ENABLE
) ;

 Is inserting a new record in No.5 is possible? Why and why not? Explain the reason why? Yes, it is
very much possible to insert a new record because the data is unique.
6. Add again a new record as shown below:
10 ARRIANE SALAMAT ASALAMAT TEACHER 260 8 BRGY.MANGINO
5 0 0
 Is inserting a new record in No.6 is possible? Why and why not? Explain the reason why? No. An
error has occurred which is error ORA – 00001 meaning, I was trying to insert an already existing
data in a restricted field. For this table, the column ID is a restricted field. ORA-00001 message is
shown when a unique constraint has been violated.
7. Add again a new record as shown below:
10 RAYCHELOU VALENCI RVALENCIA DEAN 5000 8 CANIOGAN ST. DR.
6 A 0 0 SIXTO BLDG. PASIG

 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. It is not possible to insert this new record. The value
entered in the address column string is too large. The maximum size is 20, the actual size is 34.
Modification were made to be able to add the record.
alter table "EMPLOYEE_RECORD2" modify
("ADDRESS" CHAR(34))
/
Tabl Dat Indexe Mode Constraint Grant UI Trigger Dependencie
e a s l s s StatisticsDefaults s s SQL
CREATE TABLE "EMPLOYEE_RECORD2"
( "ID" NUMBER(6,0),
"FIRSTNAME" VARCHAR2(10) NOT NULL ENABLE,
"LASTNAME" VARCHAR2(10),
"EMAIL" VARCHAR2(15),
"JOB_ID" VARCHAR2(15),
"SALARY" NUMBER(6,0),
"DEPT_ID" NUMBER(6,0),
"ADDRESS" CHAR(34),
CONSTRAINT "EMPLOYEE_RECORD2_PK" PRIMARY KEY ("ID") ENABLE
) ;

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.
select "EMPLOYEE_RECORD2"."JOB_ID" as "JOB_ID",
"EMPLOYEE_RECORD2"."SALARY" as "SALARY"
from "EMPLOYEE_RECORD2" "EMPLOYEE_RECORD2"
where "EMPLOYEE_RECORD2"."JOB_ID" 90
and "EMPLOYEE_RECORD2"."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.
select "EMPLOYEE_RECORD2"."LASTNAME" as "RAJS"
from "EMPLOYEE_RECORD2" "EMPLOYEE_RECORD2"
where "EMPLOYEE_RECORD2"."LASTNAME" DE LEON
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_RECORD2
Set Job_ID='Ad_pres', Salary='250000'
Where ID = 143

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.
12. Delete from EMPLOYEE_RECORD2
WHERE ID = 100
13. 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.
2% 10%
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 17000; Where salary = 17340;
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 9000; Where salary = 9180;
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 5800; Where salary = 5916;
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 2600; Where salary = 2652;
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 50000; Where salary = 51000;
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 6000; Where salary = 6120;
Update EMPLOYEE_RECORD2 Update EMPLOYEE_RECORD2
Set salary = salary *1.02 Set salary = salary *1.10
Where salary = 250000; Where salary = 255000;
14. Email address is not being use, and save space you have to delete the said column.
alter table "EMPLOYEE_RECORD2" drop column
"EMAIL"

/
15. Select the table now and draw the final output after you perform the DDL and DML statements.

16. What will happen if the accidentally type DELETE * FROM EMPLOYEES without issuing WHERE
condition? If I accidentally type DELETE * FROM EMPLOYEES without issuing WHERE condition,
all records will be deleted.

You might also like