Reputation: 5758
What is the right method to testing mysql query?
Example: i want to testing running update query
update `transaction` set date="2013-01-01" where id=1;
after the query update, i see the database is change correctly. but then i want the database revert back to the state before the query update execute, because that's query purpose is for testing only.
Is there any tools to easily create virtual database to testing or maybe mysql have functions to revert back the state?
Upvotes: 2
Views: 4066
Reputation: 22656
As Barmar suggested. Use a test database. However if you're making a scary change to a live database and have tested it on a test database it can set your mind at ease to use transactions to confirm the live changes are as you expect. For this you can use transactions.
START TRANSACTION;
UPDATE foo SET baz = "bar";
SELECT baz FROM foo;-- Shows bar
ROLLBACK; -- Alternatively 'COMMIT'
SELECT baz FROM foo;-- Shows whatever was there previously.
Note that changes to schema are not transactional (i.e. altering tables cannot be rolled back).
Upvotes: 2