Syntax for SQL transactions

To put a SQL query in a TRANSACTION and COMMIT the transaction, you can use the following sample syntax:

START TRANSACTION;
UPDATE tablename
SET col1 = 'value1';
COMMIT;

To put a SQL query in a TRANSACTION and ROLLBACK the transaction, you can use the following sample syntax:

START TRANSACTION;
UPDATE tablename
SET col1 = 'value1';
ROLLBACK;

To put a SQL query in a TRANSACTION using savepoints to ROLLBACK the transaction, you can use the following sample syntax:

START TRANSACTION;
SAVEPOINT firstsavepoint;
INSERT INTO tablename
SELECT * FROM anothertablename
WHERE col1 = 'value1';
SAVEPOINT secondsavepoint;
DELETE FROM tablename
WHERE col1 = 'value2';
ROLLBACK TO firstsavepoint;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.196.175