COMMIT amalinining qo`llanilishi
-- Start a transaction
BEGIN TRANSACTION;
-- SQL statements within the transaction
UPDATE table_name SET column1 = value1 WHERE condition;
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
-- Commit the transaction to make changes permanent
COMMIT;
-- Start a transaction
BEGIN TRANSACTION;
-- Update the version number of software with ID 1
UPDATE Software SET version_number = '2.0' WHERE software_id = 1;
-- Commit the transaction to make the change permanent
COMMIT;
Rollback amalini bajarilishi
-- Start a transaction
BEGIN TRANSACTION;
-- Update the version number of software with ID 1
UPDATE Software SET version_number = '2.0' WHERE software_id = 1;
-- Check for a condition (this could be an error check)
IF some_condition THEN
-- Rollback the transaction to undo the changes
ROLLBACK;
ELSE
-- Commit the transaction to make the change permanent
COMMIT;
END IF;
-- Start a transaction
BEGIN TRANSACTION;
-- Update the version number of software with ID 1
UPDATE Software SET version_number = '2.0' WHERE software_id = 1;
-- Check for a condition (this could be an error check)
IF some_condition THEN
-- Rollback the transaction to undo the changes
ROLLBACK;
PRINT 'Transaction rolled back.';
ELSE
-- Commit the transaction to make the change permanent
COMMIT;
PRINT 'Transaction committed.';
END IF;
SAVEPOINT tranzaksiyasini ishlatilishi
-- Start a transaction
BEGIN TRANSACTION;
-- Update the version number of software with ID 1
UPDATE Software SET version_number = '2.0' WHERE software_id = 1;
-- Create a savepoint
SAVEPOINT my_savepoint;
-- Attempt to update another software record
UPDATE Software SET version_number = '3.0' WHERE software_id = 2;
-- Check for a condition (this could be an error check)
IF some_condition THEN
-- Rollback to the savepoint
ROLLBACK TO my_savepoint;
PRINT 'Rolled back to savepoint.';
ELSE
-- Commit the transaction to make the change permanent
COMMIT;
PRINT 'Transaction committed.';
END IF;
-- Start a transaction
BEGIN TRANSACTION;
-- Update the version number of software with ID 1
UPDATE Software SET version_number = '2.0' WHERE software_id = 1;
-- Create a savepoint
SAVEPOINT my_savepoint;
-- Attempt to update another software record
UPDATE Software SET version_number = '3.0' WHERE software_id = 2;
-- Check for a condition (this could be an error check)
IF some_condition THEN
-- Rollback to the savepoint
ROLLBACK TO my_savepoint;
PRINT 'Rolled back to savepoint.';
ELSE
-- Commit the transaction to make the change permanent
COMMIT;
PRINT 'Transaction committed.';
END IF;
Dostları ilə paylaş: |