mysql 交易_交易MySQL

如果SQL语句中有任何错误,系统将自动回滚更改,如何启动事务?

我有以下SQL语句

START TRANSACTION;

BEGIN;

INSERT INTO `users`(id,name,gender,email,age)

VALUES(11121,'sss',0,'ssss',22);

INSERT INTO `teachers`(`UserId`,`teachingSubject`)

VALUES(11121,300);

COMMIT;

当第二个语句计数错误时,它不会回滚.为什么? ‘teachingSubject’是TINYINT(2),第二个语句将超出其范围.我想回滚所有的陈述.

Below is my procedure.

mysql> source d:\s.sql

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

ERROR 1264 (22003): Out of range value for column 'te

Query OK, 0 rows affected (0.09 sec)

mysql> SELECT * FROM teachers

-> ;

+--------+-----------------+

| UserId | teachingSubject |

+--------+-----------------+

| 11111 | 1 |

| 11112 | 9 |

| 11113 | 100 |

+--------+-----------------+

3 rows in set (0.00 sec)

mysql> SELECT * FROM users;

+-------+--------+--------+----------------+------+

| id | name | gender | email | age |

+-------+--------+--------+----------------+------+

| 11111 | Killer | | ssss@sss | 12 |

| 11112 | sss | | ssss | 22 |

| 11113 | sss | | ssss | 22 |

| 11114 | sss | | ssss | 22 |

| 11115 | sss | | ssss | 22 |

| 11116 | sss | | ssss | 22 |

| 11117 | sss | | ssss | 22 |

| 11118 | sss | | ssss | 22 |

| 11119 | sss | | ssss | 22 |

| 11120 | sss | | ssss | 22 |

| 11121 | sss | | ssss | 22 |

| 12345 | Sefler | | sefler@125.com | 12 |

+-------+--------+--------+----------------+------+

12 rows in set (0.00 sec)

教师表中没有id = 11121的记录,但是用户表没有.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值