START TRANSACTION; -- 트랜잭션 시작
SELECT * FROM members; -- 초기 상태 보여줌
INSERT INTO members VALUES(1, '이순신', '2020-02-02'); -- 데이터 수정
SELECT * FROM members; -- 수정 상태 보여줌
COMMIT -- 트랜잭션을 DB에 적용
SELECT * FROM members; -- 적용된 결과 조회
START TRANSACTION; -- 트랜잭션 시작
SELECT * FROM members; -- 초기 상태 보여줌
INSERT INTO members VALUES(1, '이순신', '2020-02-02'); -- 데이터 수정
SELECT * FROM members; -- 수정 상태 보여줌
ROLLBACK -- 트랜잭션을 취소하고 START TRANSACTION 실행 전 상태로 롤백함
SELECT * FROM members; -- 조회
DELETE FROM TRAT3 WHERE ID=2012;
COMMIT;
SAVEPOINT S1;
DELETE FROM TRAT3 WHERE ID=2014;
SAVEPOINT S2;
DELETE FROM TRAT3 WHERE ID=2015;
SAVEPOINT S3;
DELETE FROM TRAT3 WHERE ID=2011;
ROLLBACK TO S2;
DELETE FROM TRAT3 WHERE ID=2012;
COMMIT;
SAVEPOINT S1;
DELETE FROM TRAT3 WHERE ID=2014;
SAVEPOINT S2;
DELETE FROM TRAT3 WHERE ID=2015;
SAVEPOINT S3;
DELETE FROM TRAT3 WHERE ID=2011;
ROLLBACK TO S2;
SELECT * FROM TRAT3;
COMMIT;
ROLLBACK TO S1;
-- 오토커밋 off
SET AUTOCOMMIT = 0;
-- 오토커밋 on
SET AUTOCOMMIT = 1;
-- 오토쿼리 설정 확인
SELECT @@autocommit;
Reference
1) https://jerryjerryjerry.tistory.com/48
2) https://inpa.tistory.com/entry/MYSQL-%F0%9F%93%9A-%ED%8A%B8%EB%9E%9C%EC%9E%AD%EC%85%98Transaction-%EC%9D%B4%EB%9E%80-%F0%9F%92%AF-%EC%A0%95%EB%A6%AC