1. SQL Midterm
To Purchase This Material Click below Link
http://www.tutorialoutlet.com/all-miscellaneous/sql-
midterm/
FOR MORE CLASSES VISIT
www.tutorialoutlet.com
SQL Midterm (200 points max)
General Instructions: You must use Dropbox in Folio for posting
strictly individual solutions. In addition use the
provided cover page, from the syllabus, and elaborate lessons learned
(reflection of the problems and your efforts, your
conclusion regarding the value of performance analysis of SQL query
alternative, and anything else worth remembering
from this assignment). No late submission will be accepted, and you
are strongly advised to work over a period of at
least 10 days while planning to complete all at least one day before
the deadline.
Part I problem set. (100 points). This portion deals with the DB
evolution, expect to invest min 8-10 hours of work.
ITEM DEPAR TMENT item name dept name item type
item color empid (FK)
dept f loor
dept phone
2. QSALE
saleno EMPLOY EE Saleqt y
dept name (FK)
item name (FK) empid
empf name
emplname
empsalary
empaddres s
dept name (FK)
boss (FK) SUPLIER
suplid
DELIVER Y
delidsuplname
supladdressdelqt y
suplid (FK)
delinstruc t
itemname (FK)
dept name (FK) Starting with the QSALE DB, implemented in
Oracle, apply the following changes to the DB definitions and/or
content:
Step 1: Add delivery-date and sales-date toData
QDEL
3. andillustrating
QSALE tables
and populate (update them) with random dates in
Model
QSALE,
2010 and 2011 respectively.
the SQL Playbook databse
Step 2: Add QtyOnHand field for representing the quantity i.e. level
of a current inventory in QITEM table and set up
initial (but not default) values to a 100.
Step 3: Update QITEM inventory as follows:
a Using QDEL existing records (as a basis for transaction) subtract if
delivery was to a consuming (administrative
or management departments, make a view of those first), and add to
the inventory if delivery was to other
departments.
b Similarly use existing QSALE records (as a basis for transactions)
to diminish the inventory.
c Provide Inventory status report indicating QtyOnHand under ‘safe’
level of 100.
d How would you, for all items with a quantity on hands value under
a 100, trigger (i.e. automate) a delivery, of a
random replenishing value between 100 and 200, to (only the) sale
departments with the sales that depleted an
4. item to level under 100?
e How would you take care, if necessary, in cases of items that had no
deliveries (unknown supplier) or sales
attempting to sell more than the available quantity on hand?
f
Suggestion: Visualize DB before starting process of changes and
visualize every structural content change
Note: Test all work/changes above as you go (typically using select *
from … statements).
Step 4: Purpose of this step is mainly to transfer recursive relationship
form QEMP to a new table replacing QDEPT
a) Reconstruct QEMP table so that BOSS information from QEMP
table became MANAGER information in a
new QORG table (to be derived from QDEPT). Expand the QORG by
inserting a ‘SUNRISE’ (company) as
organizational unit managed by the top BOSS (but use a query on
QEMP to determine the top BOSS,
employee that have no BOSS but serving as a BOSS to at least one
other employee.
Discuss potential difficulties in reporting if you have the same person
managing more than one department
or the whole company in addition to one of the departments.
After accomplishing previous tasks of this step, the QEMP table will
also need to be changed in the following manner:
b) add employment dates, for every employee using random dates in
2007,
5. c) remove the BOSS information from QEMP. d) The old QDEPT is
to be deletinformation is
successfully migrated to new QORG table. Step 5: Insert five
salespersons, hired as employees working in departments involved
with sales in the 2012 (insert five
records with made up employment date in 2013).
Step 6: Create QCUSTOMER table with 20 prospects and generate
one possible sale to each in 2014, keeping inventory
information updated (automatically if possible). Note a need to
expand QSALE to include FK of the customer (an
optional field as they could still be some sales made by unidentified
customers as well as for a backward compatibility).
Step 7: In January 2015 the SUNRISE company started accepting
mail orders for multiple ITEMS and started fulfilling
sales for them assuming sufficient inventory. To keep old system
intact new tables are to be created to handle multiline
order fulfillment. Show DDL code (for new tables ORDER and
ORDERLINE) and illustrate with a few transactions
(inserts producing new representative records). The SUNRISE in
January 2015 also started to accept payments by
Credit card for all mail orders whenever inventory is sufficient.
Step 8: SUNRISE is adding its own automatic orders SORDERS to
suppliers to initiate delivery of all ITEMS when
their quantity at hand reaches a certain minimal level (but now instead
of a 100 being the safe level, company opted for
variable level declared to be equivalent to the 10% of the item’s
average qty on hand for the past year. Please note that a
6. running average needs to be calculated during the current year and
kept for the past year as well). So discuss what
triggers needs to be made that will use a function for calculating
running avg and maintaining safe levels of the
inventory. How would you prepare, in 2016, for this new functionality
in order to be ready for 2017 (especially
automating end of year processing).
Step 9: SUNRISE is considering expanding the DB with INVOICES
to old customers (if inventory on hand cannot
completely fulfill an order), but will still accept new customers for
orders that can be completely fulfilled from on hand
inventory.
Step 10: To demonstrate value of the newly completed DB design,
create four intermediate level SQL queries, not
possible with the old QSALE DB design, illustrating interests of
various stakeholders (managers, customers, suppliers,
and employees). In addition create necessary views to assure that any
queries that worked with the original QSALE DB
work without changes. Part II problem set (100 points max). Expected
effort is 5+ hours. This part will cover exploration of SQL query
alternatives for selected problem patterns. You can user both
SQL Server and Oracle (in case of differ possible syntax) but to count
each query must be true alternative
meaning their execution/explain plans must be different. Always
inspect data content first to visualize what
can be expected. Make sure to test your code and demonstrate validity
of each solution!
7. Here the number of correct queries and their originality count towards
the grade.
Problem #1 (50 points max) – not so easy
Given a QDEL table from the (old i.e. original) QSALE DB provide
as many alternatives in SQL to select every fifth
record.
Problem #2 (50 points max) – moderate
Given a QITEM table, from the QSALE DB, copy its content into
NEWITEM table. Make three unrelated but elementary changes (one
record update, one new record insert, and one old
record delete) in NEWITEM table.
a) Provide as many different ways using SQL (but no stored
procedures or triggers) to accomplish the
following task: compare the tables QITEM and NEWITEM to assess
if they are now exactly the same.