start transactionでトランザクションをはじめる。
- コミットでSQL文を実行する。
- ロールバックでSQL文を実行しない。
ためす
mysql> start transaction; Query OK, 0 rows affected (0.00 sec) mysql> insert into Country (Code, Name, Continent, Region, SurfaceArea, IndepYear, Population, LifeExpectancy, GNP, GNPOld, LocalName , GovernmentForm , HeadOfState , Capital , Code2 ) value ('YKD', 'YukariKingdom', 'Asia', 'Asia', 999.99, 2004, 100000, 78.5, 100000.00, 100000.00, 'YukariKingdom', 'Monarchy', 'Yukari Tamura', 133, 'YK'); Query OK, 1 row affected (0.00 sec) mysql> select * from Country where Code = 'YKD'; +------+---------------+-----------+--------+-------------+-----------+------------+----------------+-----------+-----------+---------------+----------------+---------------+---------+-------+ | Code | Name | Continent | Region | SurfaceArea | IndepYear | Population | LifeExpectancy | GNP | GNPOld | LocalName | GovernmentForm | HeadOfState | Capital | Code2 | +------+---------------+-----------+--------+-------------+-----------+------------+----------------+-----------+-----------+---------------+----------------+---------------+---------+-------+ | YKD | YukariKingdom | Asia | Asia | 999.99 | 2004 | 100000 | 78.5 | 100000.00 | 100000.00 | YukariKingdom | Monarchy | Yukari Tamura | 133 | YK | +------+---------------+-----------+--------+-------------+-----------+------------+----------------+-----------+-----------+---------------+----------------+---------------+---------+-------+ 1 row in set (0.00 sec) mysql> rollback; Query OK, 0 rows affected (0.00 sec) mysql> select * from Country where Code = 'YKD'; Empty set (0.00 sec)