You are on page 1of 13

Given the following employee database:

Employee (employee_ID, employee_name, street, city, zip, manager_ID)


Works (employee_ID, company_ID, hire_date, salary)
Company (company_ID, company_name, city)

Where the primary keys are underlined with a solid line and any foreign keys are underlined with
a dashed line, give an expression in SQL for each of the following queries:

(a) Find the names and cities of residence of all employees who work for ABC
Corporation. (2 points)

SELECT employee.employee_name, employee.city
FROM employee, works, company
WHERE
employee. employee_ID = works. employee_ID
AND works. company_ID = company. company_ID
AND company. company_name = ABC Corporation



(b) Find the names, street addresses, and cities of residence of all employees who work
for ABC Corporation and earn more than $10,000. (2 points)


SELECT employee.employee_name, employee.street,
employee.city, employee.zip
FROM employee, works, company
WHERE
employee . employee_ID = works. employee_ID
AND works. company_ID = company. company_ID
AND company. company_name = ABC Corporation
AND works.salary>10000

(c) Find all employees in the database who do not work for ABC Corporation. (2 points)

SELECT employee . employee_ID , employee.employee_name
FROM employee , works, company
WHERE
employee . employee_ID = works. employee_ID
AND works. company_ID = company. company_ID
AND company. company_name <>ABC Corporation

(d) Find all companies located in the city in which ABC Corporation is located. (2 points)

SELECT company. company_name
FROM company
WHERE
company. city IN ( SELECT company. city FROM company
WHERE company. company_name = ABC Corporation )

(e) Find all employees hired on or after January 1, 2010. (Note: make sure to use a function on
the date column to ensure the date formats in the condition statement match) (2 points)

SELECT employee . employee_ID , employee.employee_name
FROM employee
WHERE employee.hire_date >= TO_DATE(01/01/2010, MM/DD/YYYY)

Part 2. The Oracle Instance and Transaction/Query Processing

(a) Illustrate the architecture of the Oracle instance, including
all memory structures, processes, and associated physical files. (5 points)



Oracle instance: It consist SGA and set of a background process.
SGA:
Java Pool: Fixed amount of the memory allocated for the JVM running in the
database. It can be resized only online while the database is up and running (Kyte,
2010, p.144).
Large pool: This is an optional area and it can be sized online. RMAN backup for
disc I/O buffers uses this memory. (Kyte, 2010, p.144).
Shared pool: shared pool contains two sub caches one is library cache, and the other
is data dictionary. Size controlled by using SHARED_POOL_SIZE initialization
parameter. It can be changed dynamically as long as it is less than SGA_MAX_SIZE
(Kyte, 2010, p.144).
Streams pool: This is new in oracle 10g. Size can be controlled using initialization
parameter (STREAMS_POOL_SIZE).
The Null pool: This one does not really have a name. It is the memory dedicated
to blocking buffer (Cached database blocks) the redo log buffer, and a fixed SGA
area .
Process: These background processes performs essential maintenance task for
keeping oracle instance running. These processes perform individual tasks and
coordinate with each other
List of the process: The process Monitor (PMON), System Monitor (SMON),
Distributed Database Recovery (RECO), Checkpoint Process (CKPT), Database
Block Writer (DBWn), Log Writer (LGWR), Archive Process (ARCn),
Diagnosability Process (DIAG), Flashback Data Archiver Process (FBDA), Database
Resource Manager Process (DBRM), General Task Execution Process (GENO),
Remaining Common Focused Process(Kyte, 2010, p.144).

(b) Explain how transactions are processed by the Oracle DBMS. (5 points)
All the oracle transactions comply with ACID properties. ACID is the set of
properties that guarantee that database transactions processed reliably (Roe, 2012).
A: all the task in the transaction committed or rolled back
C: Transaction cannot leave the database in inconsistence state means not leaving the
transaction in the middle.
I: One transaction cannot effect or depend on other.
D: Completed transaction stores in thee database permanently
Oracle Database uses ACID properties for maintaining consistency of the database at all
times (Roe, 2012).
Transaction management in the database is managing change to the database
without affecting the integrity of the database. When transaction executed it either needs
to complete its entire task (locking particular tables or database, DML operations,
unlocking) or cancel all the tasks and return to original state. For example in a small store
consider sale of a particular product in the store, it involves booking order and decreasing
quantity in the inventory table. If transaction fails in the middle of the transaction, the
entire transaction must roll back; otherwise, the available quantity in the store does not
balance with inventory table (Roe, 2012).
In Oracle, transactions are atomic means all the statements in the transaction
either completed or rolled back and individual statement with in the transaction
completely executed or rolled back. When individual statement fails in transaction, it
does not automatically rollback previous transactions (Kyte, 2010, p.268). Example:
Update statement that updates 100 records failed at record 20 will roll back to original
state. PLSQL package with no commit statements in the package returns to original state
if it fails in the middle.
(c) Explain how queries are processed by the Oracle DBMS. (5 points)












(Figure 7-3 Stages of
SQL Processing from Ashdown & Kyte, 2013)

Above diagram explains the Stages of SQL processing. Stages are parsing, optimization,
row source generation, and execution. Oracle may omit some of the steps depending on
statement (Ashdown & Kyte, 2013, SQL).

Pars Phase: The first step is parsing. In this step, it performs Syntax, Semantic, and Shared Pool
check. During this phase, oracle checks weather Query is ok and creates an execution plan. This
execution plan is stored in library cache (Burleson Consulting, 2009).
a) Syntax check: Oracle checks weather syntax of the query is right or not. For example, if misspelled
FROM it error with ORA-00923: FROM keyword not found where expected (Ashdown & Kyte,
2013, SQL).
b) Semantic Check: This checks weather queried column or tables exist in the database (Ashdown &
Kyte, 2013, SQL).
c) Shared Pool Check: Oracle performs shared pool check and determines whether to send query for
hard parse or soft parse. Database always performs hard parse for DDL statements. Database
builds new application code for the query in hard parse phase. If it is soft parse, database reuses
existing code in the shared cache (Ashdown & Kyte, 2013, SQL).
SQL Optimization: Database generates execution plans by using statistics it collected for the
data its querying. Optimizer selects most efficient plan based on the executions plans cost. All
the DML statements go through this phase at least once and DDL statements never optimized
unless it includes DML sub query (Ashdown & Kyte, 2013, SQL).
SQL Row Source Generation: The row source generator is software that receives the optimal
execution plan from the optimizer and produces an iterative plan, called the query plan that is
usable by the rest of the database (Ashdown & Kyte, 2013, SQL).
SQL Execution: This is mandatory step for all DML statements. Final stage of the operation is
closing the cursor. This fetches records or data into memory based on the execution plan it
received (Ashdown & Kyte, 2013, SQL).

Consider a database used to record the marks that students get on different examinations of
different course offerings.

(a) Construct an E-R diagram for the database that models exams as entities, and uses a
ternary relationship. (5 points)


Student
Exams
entities:
Student(Sudent_ID, Name)
Class(Course_Num, Date, Location, Department)
Takes-Exam (Sudent_ID, Course_Num, Examcode, Date, Location, Grade)
(b) Construct an alternative E-R diagram that uses only a binary relationship between
students and course_offerings. Make sure that only one relationship exists between a
particular student and course_offering pair, yet you can represent the marks that a student
gets in different exams of a course offering. (5 points)










Student Exams tables
Student(Sudent_ID, Name)
Class(Course_Num, Date, Location, Department)
Takes-Exam (Sudent_ID, Course_Num, Date, Location, Quiz grade, Lab grade,
Annotated Bibliography grade, Final exam grade, Disscussion grade)

(c) Design an E-R diagram for keeping track of the exploits of your favorite sports team.
You should store the matches played, the scores in each match, the players in each match,
and individual player statistics for each match. Summary statistics should be modeled as
derived attributes. (5 points)

Player (Name, Age, Current year_score)
Match (Match_id, Location, Opp_score, Opponent, Own_score, Date)
Played (Match_id, Location, score, Player_id)

(d) Construct an E-R diagram for a car insurance company whose customers own one or
more cars each. Each car has associated with it zero to any number of recorded accidents.
(5 points)



Car insurance tables:
Customer (SSN, Name, Address, License)
Car(Owner_SSN, Make, Year, Model, VIN, Plate_Num)
Accident (Date, Location, Report-Num)
Participated(SSN,VIN,Report-Num,Claim_Amt)

(e) A weak entity set can always be made into a strong entity set by adding to its attributes
the primary key attributes of its identifying entity set. Outline what sort of redundancy
will result if we do so. (5 points)
For example, weak entity set EMPLOYEE and DEPENDENT tables made strong
by adding employee_id from EMPLOYEE table to the DEPENDENT table. Now
employee_id exist in the both the tables and making it redundant information in the
DEPENDENT table. In addition, employee number repeats for each dependent in
DEPENDENT table.

You might also like