Chapter 7. Sessions, Transactions, and Locks

In an ideal world, a database is accessed by one and only one user, and all changes are made and saved in a proper order. In the real world, the data must be shared — it might come from different sources (some of which cannot be trusted) in a variety of formats; sometimes it comes at unusual times; and rarely, if ever, would a database server be accessed by only one user at a time.

Fortunately, relational databases were designed to work in a multiuser environment. When more than one user accesses the same set of data, a completely different set of problems arises: What data should be visible for the users? Which modification should take precedence? What is the guarantee that the data changes will not be lost during execution of a lengthy database procedure? The answer to these and many other problems comes in terms of sessions, transactions, and locks.

A transaction offers a solution to potential data consistency problems (discussed in detail later in the chapter), whereas locks deal with data concurrency problems, and the session represents the context in which, along with some other things, transactions and locks take place.

Sessions

Whatever happens in terms of communication between an RDBMS server and a user accessing it happens in the context of a session. In a multiuser environment, one of the primary concerns is data integrity. When a client application establishes a connection to an RDBMS server, it is said that it opens a session ...

Get SQL Bible, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.