• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Transactions

The last item that we discuss in this chapter is the concept of transactions and the CFTRANSACTION tag. There are two reasons that transactions are important to us. One reason is that if any one query fails, all the other queries are, in effect, failed by the database server. Transactions can also be used to prevent multiple users from editing the same data at the same time. An application that displays inventory is an example of such a situation. You obviously would not want two users attempting to modify inventory at the same time. What happens if FlyByNite Airlines enables two customers to purchase a ticket for the same seat on Flight 123 at the same time? We could easily have a situation where both customers purchase the same or the last ticket. Maybe FlyByNite Airlines is not a good example because they intentionally oversell flights, but it should demonstrate the concept; you are trying to prevent two users from modifying the data at the same time.

Let’s take this example another step. A transaction can be a series of queries that either succeeds in bulk or not at all. We are attempting to purchase a ticket on Flight 123. What are some of the tasks that would have to be accomplished for a customer to purchase a ticket? A couple of simple actions would be adding the customer information, assigning the customer a seat on the flight, and charging his or her credit card.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint