欢迎投稿

今日深度:

sqlserver 2008实现的转账事务模拟,sqlserver2008

sqlserver 2008实现的转账事务模拟,sqlserver2008


use master

drop table customer
create table customer(
id int primary key,
account decimal check(account>0),
name varchar(20)
)

--use master
alter table dbo.customer
add check(customer.account>0)

select * from customer
insert into customer values(2012090101,2000,'张三');
insert into customer values(2012090102,1000,'李四');
insert into customer values(2012090103,1000,'王五');

begin transaction
declare @sum int
set @sum=0
update customer set account-=200 where customer.id=2012090101
set @sum+=@@ERROR
update customer set account+=200 where customer.id=2012090102
set @sum+=@@ERROR

--update customer set account-=100 where customer.id=2012090103
if @sum<>0
begin
 print '转账失败'
 rollback transaction
end
else
 begin
 print '成功转账'
 commit transaction
 end
go
select * from customer


 


java需要写一个JAVA程序,模拟银行账户的查询、转账功可以

“\ T”选项卡,当输出数据显示,几乎以表格形式显示,目的是为了使数据看起来整齐点。
“\ n”换行,其他行显示下一个(...),目的是换行字符或字符串,使用System.out.println();效果是一样的。
 

我用sqlserver 2008 用发布订阅的方式 做数据交换

使用事务方式会快些,在主机上接交一个事务,基本上在订阅机上过一个1到2秒就可以看到了。
不过据部份高手说,对于数据量大的系统容易出问题。
 

www.htsjk.Com true http://www.htsjk.com/shujukunews/4126.html NewsArticle sqlserver 2008实现的转账事务模拟,sqlserver2008 use master drop table customer create table customer( id int primary key, account decimal check(account0), name varchar(20) ) --use master alter table dbo.customer add check(customer...
评论暂时关闭