You are on page 1of 4

ITTOOLS – Module 6 – Transaction Management

Submitted by Abby Gail A. Tiongson AC181

Exercise – Rollback
Read the problem carefully and write the answer on the spaces
provided for below.
#1:
We delete and restore Mrs. Hamilton from our example database.

DELETE
FROM person
WHERE id = 3; -- Lisa Hamilton

Question 1_1.

-- Is the person with id=3 really gone?

SELECT *
FROM person
WHERE id = 3;

Then try to rollback


-- ROLLBACK restores the deletion
ROLLBACK;

-- ONE hit expected !!!

SELECT *
FROM person
WHERE id = 3;

Question 1_2.
-- After rolling back, Is the data of a person where id = 3 (Hamilton’s record)
gone?

Answer 1_1. Yes, the person with id=3 is really gone or deleted from the
database because even if the transaction was not yet completed or closed by a
“commit” command, the delete command already removes the data in the
ITTOOLS – Module 6 – Transaction Management
Submitted by Abby Gail A. Tiongson AC181
database. Although there’s a chance that it still exists as the transaction is not yet
persistent.

Answer 1_2. No, the data of id = 3 (Hamilton’s record) after rolling back is not
gone or deleted in the database because rolling back will cancel the effect of a
“delete” command or any DML command for that matter.

#2:
The ROLLBACK is not restricted to one single row. It may affect several rows,
several commands, different kind of commands and even several tables.

--same as above
DELETE
FROM person
WHERE id = 3;

-- destroy all e-mail addresses


UPDATE contact
SET contact_value = 'unknown'
WHERE contact_type = 'email';

-- verify modifications
SELECT * FROM person;
SELECT * FROM contact;

Question 2_1. – 1st command - Is the person with id=3 really gone? 2nd command
- Will email address be updated?

-- A single ROLLBACK command restores the deletion in one table and the
modifications in another table

ROLLBACK;

-- verify ROLLBACK
SELECT * FROM person;
ITTOOLS – Module 6 – Transaction Management
Submitted by Abby Gail A. Tiongson AC181
SELECT * FROM contact;

--after rolling back,


Question 2_1. – 1st command - Is the person with id=3 really gone? 2nd command
- Will email address be updated?

Answer 2_1.
1st command - Yes, the record of id=3 is deleted from the person table because
of the effect of the delete command. Although, there’s a chance that it may still
exists as the transaction has not been closed so the effect of the command is still
not permanent in the database.
2nd command - Yes, the email address in the contact table has been updated
because of the update command. Although, the absence of the commit
command to close the transaction can mean that the effect of the “update”
command is not yet saved or stored in the database so sometimes the record may
not update.

Answer 2_2.
1st command - No, the person with id = 3 is not really gone or still exists because
the transaction was closed by a rollback command. The transaction was
cancelled out in the database. Thus, the command didn’t take effect.
2nd command - No, the email address in the contact table was not updated
because it was postpone by a rollback command and thus, closing the transaction
by undoing the command.

When modifying data, the DBMS writes in a first step all new, changed or deleted
data to a temporary space. During this stage the modified data is not part of the
'regular' database. If we are sure the modifications shall apply, we use the
COMMIT command. - Abby
ITTOOLS – Module 6 – Transaction Management
Submitted by Abby Gail A. Tiongson AC181

You might also like