zoukankan      html  css  js  c++  java
  • Mysql ---12 事务

    1.事务:  多条数据库操作语句DML DQL同时成功或同时失败

          参考文章:https://blog.csdn.net/Jocker_D/article/details/87384673

      

    原子性:成功都成功,失败都失败
    
    
    一致性:多用户数据一致
    
    
    
    持久性:事务提交或未提交前后数据
    
    
    
    
    隔离性: 多用户互不影响
    

      

    mysql 默认自动开启事务
    set autocommit=0;关闭
    set autocommit=1;开启
    创建事务:
        set  autocommit=0 --关闭事务自动提交
        start transaction---事务开启
            select...    
            insert into...
            update table set
            delete from..where..   --- 操作动作
        commit ---提交事务
        rollback --提交失败回滚
        set autocommit=1 ---手动开启事务
        savepoint 保存点
        rollback to savepoint ---回滚到保存点
        release  savepoint ----撤销保存点
    =====================================
    create database if not exists D character set utf8 collate  utf8_general_ci;
    use D;
    create table if not exists `account`(
    `id` int(3) not null auto_increment,
    `name` varchar(30) not null,
    `money` decimal(9,2) not null,
    primary key (`id`)
    )engine = innodb  default charset=utf8;
    insert into account(name,money)value('A',2000.00),('B',10000.00);
    
    set autocommit=0;--关闭自动提交
    start transaction --开启事务
    	update account set money=money-500 where name='A';
    	update account set money=money+500 where name='B';
    commit;--提交所有操作
    rollback;--失败回滚
    set autocommit=1;--恢复自动提交
    

      

      

  • 相关阅读:
    cf 535 A. Tavas and Nafas
    codeforces 534 A. Exam
    hust新人赛模拟 20150407 H
    hust新人赛模拟20150407 F
    hust新人赛模拟20150407 C
    hust新人赛模拟20150407 A
    [dp专题]hdu 1160 FatMouse's Speed
    [dp专题]hdu 1260 tickets
    [dp专题]G免费馅饼
    迷宫问题(bfs+记录路径)
  • 原文地址:https://www.cnblogs.com/chencn/p/12303862.html
Copyright © 2011-2022 走看看