Chapter 14 Slides
Chapter 14 Slides
Knowledge
1. Describe the use of transactions.
2. Describe the way locking helps prevent concurrency problems.
3. Describe the use of save points.
4. Describe the way the transaction isolation level affects
concurrency problems and performance.
5. Describe the options for locking selected rows and how they
can prevent concurrency problems.
6. Describe a deadlock.
7. Describe three techniques that can reduce deadlocks.
• When you move rows from one table to another table by using
INSERT and DELETE statements. Don’t delete the data from the
existing table unless it has been copied into the new table.
When we insert a second row into the invoice_line_items table, the insert fails. The
line_item_description is invalid.
We do not want to have a partial invoice in the database, so we roll back the entire
transaction. We want to have the entire transaction or nothing.
Later, we fix the line_item_description and can insert the entire invoice.
COMMIT;
COMMIT;
START TRANSACTION;
SAVEPOINT before_invoice;
COMMIT;
1. Lost updates
2. Dirty reads
3. Nonrepeatable reads
4. Phantom reads
Transaction C
You can add a FOR UPDATE clause
START TRANSACTION; to the end of a SELECT statement.
SELECT * FROM sales_reps WHERE rep_id < 5 • This locks the selected rows
FOR UPDATE NOWAIT; and any associated indexes just
COMMIT; like an UPDATE statement
does.
• Then, other transactions can’t
read or modify these rows until
A locking read that uses NOWAIT never your transaction commits.
waits to acquire a row lock. The query
executes immediately, failing with an
error if a requested row is locked.