読者です 読者をやめる 読者になる 読者になる

by shigemk2

当面は技術的なことしか書かない

トランザクションやってみよう

MySQL

start transactionでトランザクションをはじめる。

  1. コミットでSQL文を実行する。
  2. ロールバックで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)