0% found this document useful (0 votes)
62 views

Ryan Capistrano AC181: We Delete and Restore Mrs. Hamilton From Our Example Database

1. The document discusses using rollback to undo deletion and modification commands in a database. 2. It provides an example where deleting a person by ID and then rolling back brings their data back, as rollback undoes the delete command. 3. A second example deletes the same person and updates all email addresses, then rolls back. This shows that rollback can undo changes across multiple tables from different commands in a single transaction.

Uploaded by

Ryan Capistrano
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Ryan Capistrano AC181: We Delete and Restore Mrs. Hamilton From Our Example Database

1. The document discusses using rollback to undo deletion and modification commands in a database. 2. It provides an example where deleting a person by ID and then rolling back brings their data back, as rollback undoes the delete command. 3. A second example deletes the same person and updates all email addresses, then rolls back. This shows that rollback can undo changes across multiple tables from different commands in a single transaction.

Uploaded by

Ryan Capistrano
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ryan Capistrano

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 data of Mrs. Hamilton has been deleted already by the use
of DELETE command. It is an auto commit command which will take effect even
there is no commit.
Answer 1_2. No, the data of Mrs. Hamilton will still remain on the database as
the rollback command had been use. It undo the previous command that did
you use that's why when we deleted her data earlier, the data comes back again
as is nothing happened.
#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;
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. Yes, because the data has been deleted already with the use of
DELETE command. The email address will be updated as the command had been
used.

Answer 2_2. No, rolling back the transaction will make the previous command
null or void. The email address will not be updated as the rollback will affect all
the commands that the user used.

You might also like