• ADADADADAD

    mysql怎么使用事务修改表[ 建站问答 ]

    建站问答 时间:2024-12-01 19:17:34

    作者:文/会员上传

    简介:

    mysql使用事务修改表的示例:1.新建一个表,代码:create table account(id char(10) primary key,card_id varchar(20) unique,name varchar(8) not null,money float(10,2) defa

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    mysql使用事务修改表的示例:

    1.新建一个表,代码:

    create table account(

    id char(10) primary key,

    card_id varchar(20) unique,

    name varchar(8) not null,

    money float(10,2) default 0

    );

    insert into account values('1','1234567890','张三',1000);

    insert into account (id,card_id,name) values('2','0987654321','张三’);

    2.通过事务修改money字段的数据,代码:

    start transaction

    update account set money=money-100 where card_id= '1234567890';

    update account set money=money+100 where card_id= '0987654321';#此处我们故意写错DML语句

    commit;

    select * from account

    mysql怎么使用事务修改表.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载