请教关于SQL数据库的一道题目

2025-02-24 13:05:02
推荐回答(1个)
回答1:

写个存储过程
首先假设有这么一个表,有idnum
银行帐号,mima银行密码,qukuan
取款金额
cunru
存款

create
proc
yh_zz
@idnum
char(10),@mima
char(10),
@qukuan
float,@cunru
float
as
update
yinhang
set
qukuan=@qukuan
where
idnum=@idnum
and
mima=@mima
and
isnull(@cunru,0)=0
and
@qukuan
is
not
null
update
yinhang
set
zonge=zonge-@qukuan
where
idnum=@idnum
and
mima=@mima
and
isnull(@cunru,0)=0
and
@qukuan
is
not
null
update
yinhang
set
cunru=@cunru
where
idnum=@idnum
and
mima=@mima
and
@cunru
is
not
null
and
isnull(qukuan,0)=0
update
yinhang
set
zonge=zonge+@cunru
where
idnum=@idnum
and
mima=@mima
and
@cunru
is
not
null
and
isnull(@qukuan,0)=0
select
zonge
from
yinhang
where
idnum=@idnum
and
mima=@mima
exec
yh_zz
@idnum='xxxxxxx',@mima='xxxxx',@qukuan=null,@cunru=null
查询余额
exec yh_zz
@idnum='xxxxx',@mima='xxxxx',@qukuan=数字(如1000
),@cunru=null
显示取款1000后的余额
exec yh_zz
@idnum='xxxxx',@mima='xxxxx',@qukuan=null,@cunru=数字(1000)
显示存款1000后的余额