Sybase transactions: preventing lost data
We've all done it, haven't we? You'll be typing, and suddenly you'll hit the wrong key and press Enter, and before you know it, all your files are gone (or you sent a love note to your mother instead of your squeeze, or you accidently overwrote an important file with your grocery list). Well, the folks that created SQL realized that, and they gave us a way to save ourselves from ourselves: transactions.
Transactions allow you to type a command, and then undo it if it's incorrect, just like you might do in your wordprocessor. If you are going to do a dangerous action, something that might destroy your data, put it inside a transaction just to be safe. If it works okay, you can commit your changes to the database. Until you commit the changes, your database isn't changed.
Note: You can only do certain kinds of operations called ``atomic'' operations in a transaction. If you try to do a non-atomic operation, you'll get an error message like:
Msg 2762, Level 16, State 4 Server '', Line 1 The 'DROP TABLE' command is not allowed within a multi-statement transaction in the 'pubs2' database.
Maintained by John Shipman, firstname.lastname@example.org;
original by Steve Anderson
Last updated: 1997/06/25 19:51:27 UT