Professional Documents
Culture Documents
Week 5 Assignment For IT 332 Database Management
Week 5 Assignment For IT 332 Database Management
Chapter 10
1. Suppose that you are a manufacturer of product ABC, which is composed of parts A, B, and C.
Each time a new product ABC is created, it must be added to the product inventory, using the
PROD_QOH in a table named PRODUCT. Also, each time the product is created, the parts inventory,
using PART_QOH in a table named PART, must be reduced by one each of parts A, B, and C. The
sample database contents are shown in Table P10.1
a. How many database requests can you identify for an inventory update for both PRODUCT and
PART?
Two database requests are needed for an inventory update. One is used to update product
inventory, and the other is to update the parts inventory.
UPDATE PART
SET PART_QOH = PART_QOH - 1
WHERE PART_CODE IN ('A', 'B', 'C');
c. Write the complete transaction(s).
START TRANSACTION;
UPDATE PART
SET PART_QOH = PART_QOH - 1
WHERE PART_CODE IN ('A', 'B', 'C');
COMMIT;
WEEK 5 ASSIGNMENT – FIGGINS 2
e. Using the transaction log you created in Step d, trace its use in database recovery.
If a crash occurs after some updates in the transaction (e.g., after updating product ABC but before
updating parts inventory), the transaction log can be used to identify the incomplete operations.
The recovery process can then roll back the completed updates (inserting ABC) using the old values
from the log, ensuring data consistency.
If the system fails after a successful transaction commit, the transaction log confirms the
successful updates. During database recovery, the log indicates the new values (updated inventory
for parts A, B, and C) that need to be reflected in the database.
2. Describe the three most common problems with concurrent transaction execution. Explain how
concurrency control can be used to avoid those problems.
Lost updates can occur when transactions update the same data item, and the update from one
transaction is overwritten by the other before being committed. This leads to inconsistent data.
Dirty reads can occur when a transaction reads data that is currently being modified by another
uncommitted transaction, which might read inconsistent or incomplete data. This can lead to
incorrect decisions based on inaccurate information.
Non-repeatable reads occur when a transaction reads the same data item twice, and the value
changes between the reads due to another committed transaction. This can cause confusion and
make it difficult for the transaction to proceed as intended.
3. What DBMS component is responsible for concurrency control? How is this feature used to
resolve conflicts?
The DBMS can acquire locks on data items being accessed by transactions. These locks prevent
other transactions from modifying the data until the lock is released. Different locking granularities
(e.g., row-level locking, table-level locking) can be used depending on the scenario.
Concurrency control ensures that the outcome of concurrent transactions is equivalent to what
would have happened if the transactions were executed one after another in a specific serial order.
This maintains data consistency even though multiple transactions might be executing
concurrently.
WEEK 5 ASSIGNMENT – FIGGINS 3
4. Using a simple example, explain the use of binary and shared/exclusive locks in a DBMS.
Imagine a small video game store selling only two popular games: "Adventure A" and "Sports M."
The inventory for each book is stored in a database table named GAMES with columns for Game_ID
and Quantity
Scenario: Two customers (Andrew and Sarah) are trying to buy books at the same time.
o The system acquires a binary lock on the row for "Adventure A" in the GAMES table.
This prevents any other transaction from accessing this row.
o Since the row for "Adventure A" is locked, Sarah's transaction has to wait until
Andrew finishes. This can lead to delays if Andrew takes a long time to complete the
purchase.
o The system updates the Quantity for "Adventure A" to 0 and releases the lock.
o The system acquires a shared lock on the row for "Adventure A." This allows Andrew
to read the current quantity (1).
o Since it's a shared lock, Sarah can also acquire a shared lock on the same row. She
can see there's 1 copy left.
o The system upgrades Andrew's lock to an exclusive lock. This prevents Sarah from
modifying the data while Andrew updates the quantity.
o Andrew updates the Quantity for "Adventure A" to 0 and releases the lock.
5. Suppose that your database system has failed. Describe the database recovery process and the
use of deferred-write and write-through techniques.
Database recovery aims to restore the database to a consistent state after a system failure. By
performing a Redo, the system replays transaction log entries from the last checkpoint (a
consistent state of the database) to reapply committed updates. This ensures committed changes
are reflected after a crash. Another attempt is called the Undo, which involves the system scanning
WEEK 5 ASSIGNMENT – FIGGINS 4
the transaction log backward from the point of failure. If it encounters uncommitted transactions, it
uses the log entries to undo their changes, preventing partially completed updates from affecting
the database state.
WEEK 5 ASSIGNMENT – FIGGINS 5
Chapter 11
SELECT EMP_LNAME, EMP_FNAME, EMP_DOB, YEAR(EMP_DOB) AS YEAR
FROM EMPLOYEE
WHERE YEAR(EMP_DOB) = 1976;
The data sparsity is High for the EMP_DOB Column. Date of birth is typically a low cardinality
attribute, meaning it has a large number of distinct values compared to the total number of rows in
the table. In this case, each date of birth is unique for most employees.
Creating an index on EMP_DOB might be beneficial for this query, but it depends on how often you
need to search by birth year compared to updating the employee table. If we frequently query to
find employees by birth year (like in this case), an index on EMP_DOB can significantly speed up the
search. The index allows the DBMS to quickly locate rows where the birth year is 1976. On the other
hand, indexing takes up additional storage space and adds some overhead when inserting or
updating data in the EMP_DOB column.
6. What type of database I/O operations will likely be used by the query? (See Table 11.3.)
If no index exists on EMP_DOB, the most likely I/O operation used by this query would be a full table
scan (slowest) according to Table 11.3. In this scenario, the DBMS would need to read every row in
the EMPLOYEE table to identify rows where the birth year is 1976.
WEEK 5 ASSIGNMENT – FIGGINS 6
Additional Questions
1. What is concurrency control, and what is its objective?
Concurrency control refers to a set of techniques used by a database management system (DBMS)
to ensure data consistency when multiple users or processes try to access and modify the same
data concurrently (at the same time). The main goal is to ensure that updates that are made by an
individual are not overwritten by another person’s updates before they are committed. It also
prevents the potential to read data that is currently being modified.
Database statistics are summaries of data stored in a database. These summaries provide
information about the characteristics of the data, such as the number of rows and columns in each
table, the data types of columns, and the existence of indexes and their usage patterns.
SQL performance tuning involves the process of identifying and improving the performance of
queries in a database system. The goal is to ensure queries execute efficiently and retrieve data
quickly.