연구개발/MYSQL
update 전/후 데이터 반환받기
HEAD1TON
2015. 3. 3. 16:44
use test;
drop table if exists xxx_user;
create table xxx_user (
usn int not null auto_increment
, money int not null
, grade char(1) not null
, reg_date datetime
, primary key (usn)
) engine=innodb default charset=utf8mb4;
insert into xxx_user values (null, 1000, 'A', now()), (null, 2000, 'B', now()), (null, 3000, 'C', now());
select * from xxx_user;
set @uv_money_old := -999, @uv_money_new := -999;
select @uv_money_old, @uv_money_new;
select * from xxx_user where usn = 1;
update xxx_user
set money = (@uv_money_new := (@uv_money_old := money) - 50)
, grade = 'Z'
where usn = 1;
select * from xxx_user where usn = 1;
select @uv_money_old, @uv_money_new;