Imagine you have a table called `students`. You need to add a new student with the name "Ivan Ivanov" and age 20. Use a transaction to make sure the changes are either committed or rolled back in case of an error.
1. Start a transaction.
2. Add a record for the student.
3. Commit the transaction if the insert is successful.
Requirements:
The `students` table should be created with the specified structure before completing the task.
All operations must be performed inside a transaction to ensure data integrity.
Within the transaction, you should add a record with the name "Ivan Ivanov" and age 20.
The transaction should be committed (`COMMIT`) if the insert is successful.
If there is an error, the transaction should be rolled back (`ROLLBACK`) to avoid partial changes.
After the transaction is successfully completed, the `students` table should contain a record with the specified data.
-- Start the transaction
BEGIN;
-- Try to insert a new student
INSERT INTO students (name, age) VALUES ('Ivan Ivanov', 20);
-- If the insert is successful, commit the transaction
COMMIT;