首页 > 数据库 > MySQL > 正文

MySQL 5.7 的事务控制语句的简介

2024-07-24 12:34:35
字体:
来源:转载
供稿:网友
  START TRANSACTION 或 BEGIN 语句开始一个事务
 
  COMMIT 语句提交事务,使得数据的更改永久生效
 
  ROLLBACK 语句回滚事务,取消对数据的更改
 
  SET autocommit 语句禁止或启用当前会话默认的事务自动提交功能
 
  --例子
  mysql> START TRANSACTION;
  Query OK, 0 rows affected (0.00 sec)
  mysql> SELECT @A:=SUM(deptno) FROM test;
  +-----------------+
  | @A:=SUM(deptno) |
  +-----------------+
  |             150 |
  +-----------------+
  1 row in set (0.00 sec)
  mysql> UPDATE test SET deptno=@A WHERE deptno=10;
  Query OK, 1 row affected (0.05 sec)
  Rows matched: 1  Changed: 1  Warnings: 0
  mysql> commit;
  Query OK, 0 rows affected (0.01 sec)
 
  --关闭当前会话事务的自动提交功能
  mysql> SET autocommit=0;
  Query OK, 0 rows affected (0.00 sec)
  mysql> show variables like '%commit%';
  +--------------------------------+-------+
  | Variable_name                  | Value |
  +--------------------------------+-------+
  | autocommit                     | OFF   |
  | innodb_commit_concurrency      | 0     |
  | innodb_flush_log_at_trx_commit | 1     |
  +--------------------------------+-------+
  3 rows in set (0.00 sec)

(编辑:武林网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表