SQL/MX Quick Start (G06.24+, H06.03+)

HP NonStop SQL/MX Quick Start523724-002
8-1
8 Protecting Database Integrity
This section provides information about how to begin and end a transaction.
Starting a Transaction
SQL/MX enables you to define the beginning of a transaction. A transaction can
consist of multiple SQL statements. You must end your transaction either by rolling
back or by committing the changes you have made.
Example
Define the beginning of a transaction:
BEGIN WORK;
--- SQL operation complete.
Example
Enter the statements that perform the transaction. For example, double the price of all
parts with a current price less than $2000:
UPDATE PARTS
SET PRICE = PRICE * 2
WHERE PRICE < 2000;
--- 23 row(s) updated.
Tip
Defining transactions is advisable when you are performing several related operations.
For example, suppose you are inserting data about an order in both the ORDER and
ODETAIL tables. You must use several INSERT statements to enter all of the
information.
To ensure that either all of the data is successfully inserted into the tables or none of
the data is inserted, enter BEGIN WORK before the first INSERT statement. After you
successfully insert all of the rows, enter the COMMIT WORK statement. If you
encounter a problem, enter the ROLLBACK WORK statement.