Question: Please explain how the account table, the transaction table, the savepoint command, the rollback command, and the commit command are working together: CREATE TABLE account
Please explainhow the account table, the transaction table, the savepoint command, the rollback command, and the commit command are working together:
CREATE TABLE account
accountid SMALLINT UNSIGNED NOT NULL AUTOINCREMENT,
availbalance DECIMAL NOT NULL,
lastactivitydate TIMESTAMP NOT NULL DEFAULT CURRENTTIMESTAMP ON UPDATE CURRENTTIMESTAMP,
PRIMARY KEYaccountid
ENGINEInnoDB DEFAULT CHARSETutfmb;
accountid availbalance lastactivitydate
txnid txndate accountid txntypecd amount
CREATE TABLE transaction
txnid SMALLINT UNSIGNED NOT NULL AUTOINCREMENT,
txndate DATETIME NOT NULL,
accountid SMALLINT UNSIGNED,
txntypecd VARCHAR NOT NULL,
amount DECIMAL NOT NULL,
PRIMARY KEYtxnid
KEY idxfkaccountid accountid
CONSTRAINT fkaccounttxn FOREIGN KEY accountid REFERENCES account accountid ON DELETE SET NULL ON UPDATE CASCADE
ENGINEInnoDB DEFAULT CHARSETutfmb;
INSERT INTO account
accountid availbalance, lastactivitydate
VALUES ::;
INSERT INTO account
accountid availbalance, lastactivitydate
VALUES ::;
SET AUTOCOMMIT;
# try savepoint
START TRANSACTION;
SAVEPOINT beforeupdatetransactions;
INSERT INTO transaction
txndate, accountid txntypecd amount
VALUES
nowD;
INSERT INTO transaction
txndate, accountid txntypecd amount
VALUES
nowC;
SAVEPOINT beforeupdateaccounts;
UPDATE account
SET availbalance availbalance
lastactivitydate now
WHERE accountid ;
UPDATE account
SET availbalance availbalance
lastactivitydate now
WHERE accountid ;
SAVEPOINT afterupdateaccounts;
ROLLBACK TO SAVEPOINT beforeupdatetransactions;
ROLLBACK TO SAVEPOINT beforeupdateaccounts;
ROLLBACK TO SAVEPOINT afterupdateaccounts;
COMMIT;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
