SQL/MySQL/Transaction/RollBack

Материал из SQL эксперт
Перейти к: навигация, поиск

User transaction in table

   <source lang="sql">

/* mysql> select * from Student; +-----------+------------+ | StudentID | Name | +-----------+------------+ | 1 | JJ Smith | | 2 | Joe Wang | | 3 | John Lee | | 4 | Jacky Chen | +-----------+------------+ 4 rows in set (0.03 sec)

  • /

Drop table Student; CREATE TABLE Student (

  StudentID INT NOT NULL PRIMARY KEY,
  Name      VARCHAR(50) NOT NULL

)TYPE = InnoDB;

INSERT INTO Student (StudentID,Name) VALUES (1,"JJ Smith"); INSERT INTO Student (StudentID,Name) VALUES (2,"Joe Wang"); INSERT INTO Student (StudentID,Name) VALUES (3,"John Lee"); INSERT INTO Student (StudentID,Name) VALUES (4,"Jacky Chen");


BEGIN; INSERT INTO Student (StudentID, Name) VALUES (98, "Anne"); INSERT INTO Student (StudentID, Name) VALUES (99, "Julian"); ROLLBACK; select * from Student;


      </source>