Transaction simulation for SQL Server 2008 implementation

Source: Internet
Author: User

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, ' Zhang San ');
INSERT into customer values (2012090102,1000, ' John Doe ');
INSERT into customer values (2012090103,1000, ' Harry ');

BEGIN TRANSACTION
DECLARE @sum int
Set @sum =0
Update customer set account-=200 where customer.id=2012090101
Set @sum +[email protected] @ERROR
Update customer set account+=200 where customer.id=2012090102
Set @sum +[email protected] @ERROR

--update customer set account-=100 where customer.id=2012090103
If @sum <>0
Begin
print ' Transfer failed '
ROLLBACK TRANSACTION
End
Else
Begin
print ' Successful transfer '
Commit TRANSACTION
End
Go
SELECT * FROM Customer


Transaction simulation for SQL Server 2008 implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.