20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Summary<br />

Transactions ensure that users who need to modify data don’t see data that is about to be modified or in<br />

the process of being modified. Transactions lock data sets so that you can perform modifications to<br />

records without overwriting other users’ changes or allowing other users to overwrite your changes.<br />

In this chapter, you learned the following:<br />

Transactions<br />

❑ That in order to be considered a transaction, the set of statements must pass the ACID test:<br />

Atomic, Consistent, Isolated, and Durable.<br />

❑ That the original ANSI standard used only COMMIT and ROLLBACK statements, but the various<br />

database vendors have extended the standards, in particular adding the BEGIN TRANSACTION<br />

and SAVE TRANSACTION statements to add flexibility to the process of starting a transaction and<br />

allowing partial rollbacks.<br />

❑ How transaction logs allow the DBMS to record the transaction and how the statements in the<br />

transaction affect the data to protect against catastrophic failures that could corrupt the database.<br />

❑ How to use locks to control access to different levels of objects in the database, starting at the<br />

database level and working down to the individual record in a specific table. You learned that<br />

locks have an associated significant overhead, and that hundreds or thousands of users trying to<br />

get locks can cause database slowdown and general efficiency issues.<br />

❑ How locking levels can allow you to reduce the impact of locks by allowing users to see or not<br />

see locked records only when appropriate.<br />

❑ How to prevent or minimize the four common problems with concurrent data access through a<br />

good understanding of the issues involved, through an understanding of how transactions and<br />

locks work, and by the careful use of isolation levels.<br />

This has been a very technical chapter, one that is difficult to demonstrate in the typical tutorial method<br />

because of that fact that transactions and their implementation are so very vendor- and product-specific.<br />

At the same time, transactions are a key concept to correctly handling concurrency in a multiple-user<br />

database. Failure to understand the issues can lead to huge consistency problems.<br />

The next chapter covers <strong>SQL</strong> security, how users are created, and once created, how users are restricted<br />

from using or are allowed to use objects of the database. Security allows you to determine who gets to<br />

see what, as well as who is allowed to modify data in the tables that make up the database.<br />

Exercises<br />

1. Rewrite the update to the Inventory and insert data into the Rentals table using a READ<br />

COMMITTED isolation level.<br />

2. Write a SELECT statement to view all titles in the Films table using the READ UNCOMMITTED isolation<br />

level.<br />

3. Write an UPDATE query to update all inventory to CheckedOut (= ‘Y’) using the<br />

SERIALIZABLE isolation level.<br />

325

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!