Beginning SQL
Beginning SQL Beginning SQL
In spite of all of these performance issues, there are very real and powerful benefits that result from having a transaction log. Usually a machine failure, power outage, or other catastrophe has little or no effect on the database since the transaction logs record modifications. If you need to roll back changes, everything required to perform this function is available in the transaction log. Oftentimes the DBMS automatically recognizes a failure and looks at the transaction logs to figure out what needs to be done to restore the database to a consistent state. Sometimes you must use a special recovery utility to perform this function. Remember that this discussion is just conceptual. The exact implementation details will vary dramatically from DBMS to DBMS, and in fact you do not need to be concerned with these details. Turning on and off transaction logs, tuning their size, and so forth are the domain of the database administrator (DBA). If you have such a person, you are not normally allowed to even touch these database properties yourself, and you need to go through the DBA if you need them changed for some reason. What you should take away from this discussion is the concept of automatically recording every change in the transaction log and then using these log files to roll back a transaction when required. And finally, realize that the smaller database products, such as Microsoft Access, do not use transaction logs, even though they do implement transactions. If you have a catastrophic failure in the middle of a transaction, you have nothing to fall back on to help you out. Locks Locks are the key to implementing transactions in all DBMSs, and as such, the following sections spend considerable time discussing locks, how they function, how they can help ensure consistency, and especially how they can affect performance. The term lock means much the same thing in a database that it does in life, to make some thing unavailable to some people at some times. In the case of a database, it specifically means to make some data or data structure unavailable to other valid users of that data or structure for some period of time. Perhaps you need to make the entire MemberDetails table unavailable to every other user because you need to add or drop a field. Or perhaps you need to lock the data in the Inventory table so that you can select and update specific records without other users seeing inconsistent data as you do so. Locks have nothing to do with user-level security, specifically, preventing a specific user or group of users from accessing data. Their function is simply to prevent other users from momentarily accessing data while an update or other critical usage of data is under way. Furthermore, in general you don’t apply locks yourself; the DBMS applies the locks as it sees fit, although there is a LOCK TABLE syntax for acquiring a lock of an entire table. Even though you don’t generally apply locks yourself, you still need an understanding of how they operate so that you can understand how transactions impact system performance because of the locks the system applies. Locking Granularity Transactions The term granularity refers to the level or size of the structure to which a lock is applied. Most DBMSs have the ability to apply locks at many different levels within the database, and it is useful to understand what these levels are. Every lock has the potential to inconvenience other users, so you really want to apply locks to the smallest unit possible so that you minimize the inconvenience. The following sections examine granularity from the largest data unit (the entire database) down to the smallest common unit (the record). 313
- Page 616: Chapter 10 Now that you know what v
- Page 620: Chapter 10 Types of Views Given tha
- Page 624: Chapter 10 Perhaps you need to view
- Page 628: Chapter 10 Figure 10-7 Summary view
- Page 632: Chapter 10 296 This statement gives
- Page 636: Chapter 10 The CHECK OPTION plays a
- Page 642: 11 Transactions When you move out o
- Page 646: Example Data This section creates e
- Page 650: 3. Build a record in the Rentals ta
- Page 654: The other statement that the ANSI S
- Page 658: SAVE TRANSACTION Select Update Begi
- Page 662: Figure 11-5 Begin Transaction Delet
- Page 668: Chapter 11 Database There are perfe
- Page 672: Chapter 11 In order to find and fix
- Page 676: Chapter 11 When discussing locking,
- Page 680: Chapter 11 Usually, the default iso
- Page 684: Chapter 11 From Sue’s perspective
- Page 688: Chapter 11 5. At this point, you ne
- Page 694: 12 SQL Security In today’s world,
- Page 698: Setting up security begins with cre
- Page 702: ALTER USER username options ALTER U
- Page 706: In Figure 12-3, three different gro
- Page 710: How It Works After you run this sta
- Page 714: check constraints can be used in a
In spite of all of these performance issues, there are very real and powerful benefits that result from having<br />
a transaction log. Usually a machine failure, power outage, or other catastrophe has little or no effect on the<br />
database since the transaction logs record modifications. If you need to roll back changes, everything<br />
required to perform this function is available in the transaction log. Oftentimes the DBMS automatically<br />
recognizes a failure and looks at the transaction logs to figure out what needs to be done to restore the<br />
database to a consistent state. Sometimes you must use a special recovery utility to perform this function.<br />
Remember that this discussion is just conceptual. The exact implementation details will vary dramatically<br />
from DBMS to DBMS, and in fact you do not need to be concerned with these details. Turning on<br />
and off transaction logs, tuning their size, and so forth are the domain of the database administrator<br />
(DBA). If you have such a person, you are not normally allowed to even touch these database properties<br />
yourself, and you need to go through the DBA if you need them changed for some reason. What you<br />
should take away from this discussion is the concept of automatically recording every change in the<br />
transaction log and then using these log files to roll back a transaction when required.<br />
And finally, realize that the smaller database products, such as Microsoft Access, do not use transaction<br />
logs, even though they do implement transactions. If you have a catastrophic failure in the middle of a<br />
transaction, you have nothing to fall back on to help you out.<br />
Locks<br />
Locks are the key to implementing transactions in all DBMSs, and as such, the following sections spend<br />
considerable time discussing locks, how they function, how they can help ensure consistency, and especially<br />
how they can affect performance. The term lock means much the same thing in a database that it<br />
does in life, to make some thing unavailable to some people at some times. In the case of a database, it<br />
specifically means to make some data or data structure unavailable to other valid users of that data or<br />
structure for some period of time. Perhaps you need to make the entire MemberDetails table unavailable<br />
to every other user because you need to add or drop a field. Or perhaps you need to lock the data in the<br />
Inventory table so that you can select and update specific records without other users seeing inconsistent<br />
data as you do so.<br />
Locks have nothing to do with user-level security, specifically, preventing a specific user or group of<br />
users from accessing data. Their function is simply to prevent other users from momentarily accessing<br />
data while an update or other critical usage of data is under way. Furthermore, in general you don’t<br />
apply locks yourself; the DBMS applies the locks as it sees fit, although there is a LOCK TABLE syntax for<br />
acquiring a lock of an entire table. Even though you don’t generally apply locks yourself, you still need<br />
an understanding of how they operate so that you can understand how transactions impact system performance<br />
because of the locks the system applies.<br />
Locking Granularity<br />
Transactions<br />
The term granularity refers to the level or size of the structure to which a lock is applied. Most DBMSs<br />
have the ability to apply locks at many different levels within the database, and it is useful to understand<br />
what these levels are. Every lock has the potential to inconvenience other users, so you really want<br />
to apply locks to the smallest unit possible so that you minimize the inconvenience. The following sections<br />
examine granularity from the largest data unit (the entire database) down to the smallest common<br />
unit (the record).<br />
313