Sumatra, Ferraris, Garrido - Tsa2

You might also like

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

CCS0021 LABORATORY

TECHNICAL ASSESSMENT 2

JAN ROME SUMATRA, KYLA FERRARIS, FRANCES GARRIDO

Part 1:

Instructions: Using the diagram below, write the DDL code to create the following entities into tables.
The relationships of the tables should also be written on the code. You can use SQL developer to solve
this. Copy and paste the codes below. Save the SQL scripts as Tech6_fullname. Save this document as
Tech2Document_fullname.
CREATE TABLE "DBASE3"."TIMECATEGORY"

( "IDTIMECATEGORY" TIMESTAMP (6) NOT NULL ENABLE,

"NAME" VARCHAR2(20 BYTE),

"DESCRIPTION" VARCHAR2(20 BYTE),

"CREATEAT" VARCHAR2(20 BYTE),

"UPDATEDAT" VARCHAR2(20 BYTE),

"COLUMN1" VARCHAR2(20 BYTE),

CONSTRAINT "TIMECATEGORY_PK" PRIMARY KEY ("IDTIMECATEGORY")

USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255

TABLESPACE "USERS" ENABLE

) SEGMENT CREATION DEFERRED

PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

TABLESPACE "USERS" ;

CREATE TABLE "DBASE3"."TIMESHEET"

( "IDTIMESHEET" TIMESTAMP (6) NOT NULL ENABLE,


"NAME" VARCHAR2(20 BYTE),

"COLUMN1" VARCHAR2(20 BYTE),

"COLUMN2" NUMBER,

"COLUMN3" FLOAT(63),

"COLUMN4" VARCHAR2(20 BYTE),

"ENABLED" VARCHAR2(20 BYTE),

"COLUMN5" VARCHAR2(20 BYTE),

CONSTRAINT "TABLE1_PK" PRIMARY KEY ("IDTIMESHEET")

USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255

TABLESPACE "USERS" ENABLE

) SEGMENT CREATION DEFERRED

PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

TABLESPACE "USERS" ;

CREATE TABLE "DBASE3"."USERR"

( "IDUSER" NUMBER NOT NULL ENABLE,

"NAME" VARCHAR2(20 BYTE),

"LASTNAME" VARCHAR2(20 BYTE),

"EMAIL" VARCHAR2(20 BYTE),

"USERNAME" VARCHAR2(20 BYTE),

"PASSWORD" VARCHAR2(20 BYTE),

"CREATEDAT" VARCHAR2(20 BYTE),

"UPDATEDAT" VARCHAR2(20 BYTE),

"COLUMN1" VARCHAR2(20 BYTE),

CONSTRAINT "USERR_PK" PRIMARY KEY ("IDUSER")

USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255

TABLESPACE "USERS" ENABLE

) SEGMENT CREATION DEFERRED


PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

TABLESPACE "USERS" ;

CREATE TABLE "DBASE3"."TASKS"

( "NAME" VARCHAR2(20 BYTE),

"ID_TASKS" NUMBER(11,0) NOT NULL ENABLE,

"DESCRIPTION" VARCHAR2(20 BYTE),

"COLUMN1" VARCHAR2(20 BYTE),

"ID_PROJECT" VARCHAR2(20 BYTE),

"COLUMN2" DATE,

"ENDDATE" DATE,

"CREATEAT" VARCHAR2(20 BYTE),

"UPDATEAT" VARCHAR2(20 BYTE),

CONSTRAINT "TASKS_PK" PRIMARY KEY ("ID_TASKS")

USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS

TABLESPACE "USERS" ENABLE

) SEGMENT CREATION DEFERRED

PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

TABLESPACE "USERS" ;

Part 2:

Answer the following numbers using the table given. Use SQL developer to solve this.

Save the SQL script as: Tech7_fullname. Make sure you make the questions in the worksheet as
comments.

Then copy your answer and paste your code below each number in this document.
Use the table above to answer the following by writing the SQL code. Do this code in sequential
order. Each number is related to the previous number.

Use the table above to answer the following by writing the SQL code. Do this code in sequential
order. Each number is related to the previous number.

1. Create the table above. Job_id is the primary key.

create table jobs (

job_id varchar2(10),

job_title varchar2(35),

min_salary number(6,0),

max_salary number(6,0),

constraint jobs_pk primary key(job_id)

)
2. Add a new column on the table named job_category that accepts a string and it can be
null.

ALTER TABLE jobs

ADD job_category VARCHAR2(20) NULL;


3. Using the new table, insert a new row on the Jobs table. Use the following data: Job_id:
ST_Assist, Job_title: Stock Aid, Min_Salary: 5000, Max_salary: 13000, job_category:
M_Operator.

INSERT INTO jobs (job_id, job_title, min_salary, max_salary, job_category)

VALUES ('ST_Assist', 'Stock Aid', 5000, 13000, 'M_Operator');

4. Show the all the jobid, job title, the sum of the minimum salaries of the employees and
the average of the minimum salaries of the employees that has an job title that ends
with “Representative”. Group it by their job_ids and job_titles. Show only the sum of the
MIN_salaries that are less than 5000. Then arrange it by job_id. (Then draw the table of
the result).

Select job_id, job_title from jobs


Select Sum(min_salary) from jobs

Select Avg(min_salary) from jobs


Part 3:
Write a correct SQL statement for each problem and show the result of the statement. Use the tables below. You
may use SQL developer to help you with answering the questions. Copy and past the source code and the result
after each question.

Student
Student
Enrollment
StudentId StudName Age
EnrollmentId EnrollmentDate StudentId SubjId
A Mark 18 E100 Oct – 10 - 2015 A 1
B Matthew 17 E101 Oct – 11 - 2015 B 2
C Ruth 20 E102 Nov – 10 - 2015 C 3
E103 Dec – 15 – 2015 D 1
D John 15
E104 Feb – 1 – 2015 E 3
E Sally 18
E105 Mar – 10 – 2015 F 2
F James 17

Subject
SubjId SubjDescription Units Priceperunit
1 Math 3 400
2 Science 2 500
3 History 1 250

1. Select max(units) from subject;


Select min(units) as minunits form subject;

2. Select StudName, EnrollementDate, SubjDescription


From student
INNER JOIN enrollment
ON
StudentID=StudentID
INNER JOIN subject sub
ON
SubjID=SubID
WHERE sub.SubjID IN (1,2)
3. CREATE VIEW EnrollDate AS
SELECT e.EnrollmentDate
FROM student s
INNER JOIN enrollment e
ON
s.StudentId = e.StudentId
INNER JOIN subject sub
ON
s. StudentID = sub.SubjId
WHERE sub. SubjId =3;

4. CREATE VIEW StudentDetails AS


SELECT s.StudName, e.EnrollmentDate,sub.Priceperunit*sub.Units as
TotalPriceperunit,sub.SubjDescription
FROM student s
INNER JOIN enrollment e
ON
s.StudentId=e.StudentId
INNER JOIN subject sub
ON
e. SubjId= sub SubjId
WHERE sub. SubjId IN (2,3);

5. CREATE VIEW BiggestPrice AS


SELECT sub.SubjId, sub.Priceperunit*sub.Units AS TotalPrice
From subject sub
Where sub.Priceperunit*sib.Units>1000.

1.)

You might also like