|
MariaDB [hellodb]> START TRANSACTION; # 启动事物功能
Query OK, 0 rows affected (0.00 sec)
MariaDB [hellodb]> DESC courses;
+----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+----------------+
| CourseID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| Course | varchar(100) | NO | | NULL | |
+----------+----------------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
MariaDB [hellodb]> SELECT * FROM courses;
+----------+----------------+
| CourseID | Course |
+----------+----------------+
| 1 | Hamo Gong |
| 2 | Kuihua Baodian |
| 3 | Jinshe Jianfa |
| 4 | Taiji Quan |
| 5 | Daiyu Zanghua |
| 6 | Weituo Zhang |
| 7 | Dagou Bangfa |
+----------+----------------+
7 rows in set (0.01 sec)
MariaDB [hellodb]> INSERT INTO courses (Course) VALUES ('Zabbix'),('Puppet'); # 插入一行数据
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
MariaDB [hellodb]> SELECT * FROM courses;
+----------+----------------+
| CourseID | Course |
+----------+----------------+
| 1 | Hamo Gong |
| 2 | Kuihua Baodian |
| 3 | Jinshe Jianfa |
| 4 | Taiji Quan |
| 5 | Daiyu Zanghua |
| 6 | Weituo Zhang |
| 7 | Dagou Bangfa |
| 8 | Zabbix |
| 9 | Puppet |
+----------+----------------+
9 rows in set (0.00 sec)
MariaDB [hellodb]> DELETE FROM courses WHERE CourseID=3; # 删除一行数据
Query OK, 1 row affected (0.00 sec)
MariaDB [hellodb]> SELECT * FROM courses;
+----------+----------------+
| CourseID | Course |
+----------+----------------+
| 1 | Hamo Gong |
| 2 | Kuihua Baodian |
| 4 | Taiji Quan |
| 5 | Daiyu Zanghua |
| 6 | Weituo Zhang |
| 7 | Dagou Bangfa |
| 8 | Zabbix |
| 9 | Puppet |
+----------+----------------+
8 rows in set (0.00 sec)
MariaDB [hellodb]> ROLLBACK; # 如果这时我们后悔了,可以执行回滚操作
Query OK, 0 rows affected (0.00 sec)
MariaDB [hellodb]> SELECT * FROM courses; # 查看可以发现又会到原来开始的状态了
+----------+----------------+
| CourseID | Course |
+----------+----------------+
| 1 | Hamo Gong |
| 2 | Kuihua Baodian |
| 3 | Jinshe Jianfa |
| 4 | Taiji Quan |
| 5 | Daiyu Zanghua |
| 6 | Weituo Zhang |
| 7 | Dagou Bangfa |
+----------+----------------+
7 rows in set (0.00 sec)
|
|
|