Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views1 page

SQL02 Transaction

Uploaded by

h3444850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

SQL02 Transaction

Uploaded by

h3444850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

DROP TABLE Accounts;

CREATE TABLE Accounts (


AccountNumber INT PRIMARY KEY,
AccountHolder VARCHAR(100) NOT NULL,
Balance DECIMAL(10, 2) NOT NULL
);

BEGIN TRANSACTION;

INSERT INTO Accounts (AccountNumber, AccountHolder, Balance)


VALUES
(101, 'John Doe', 5000.00),
(102, 'Jane Smith', 7500.50),
(103, 'Bob Johnson', 12000.25),
(104, 'Alice Brown', 3000.75);
Commit;

select * from Accounts;

BEGIN TRANSACTION;

UPDATE Accounts SET Balance = Balance - 100 WHERE AccountNumber = 101;


UPDATE Accounts SET Balance = Balance + 100 WHERE AccountNumber = 102;
SELECT * FROM Accounts;

ROLLBACK;

SELECT * FROM Accounts;

BEGIN TRANSACTION;

UPDATE Accounts SET Balance = Balance - 100 WHERE AccountNumber = 101;


UPDATE Accounts SET Balance = Balance + 100 WHERE AccountNumber = 102;

SELECT * FROM Accounts;

commit;
SELECT * FROM Accounts;

/*
A transaction is a sequence of operations performed on a database
as a single logical unit of work. The effects of all the SQL statements
in a transaction can be either all committed (applied to the database)
or all rolled back (undone from the database).
*/

You might also like