Home > Archive > MS SQL Server > March 2006 > about Transaction's problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author about Transaction's problem
κÊöÀÚ

2006-03-05, 8:24 pm

There is a table named users in my database.
It has two colume:
userName varchar(20)
age int

now I execute the follow transaction:

begin tran
insert users (userName,age) values ('mark',25)
insert users (userName,age) values ('jack',257777777777
7767777)
commit tran

obviously,the second setence has an overflow error,
the question is:has the first record been inserted into the users table?
why?



David Browne

2006-03-05, 8:24 pm


"κÊöÀÚ" <weisl@netstars.com.cn> wrote in message
news:%23T$6pCrPGHA.140@TK2MSFTNGP12.phx.gbl...
> There is a table named users in my database.
> It has two colume:
> userName varchar(20)
> age int
>
> now I execute the follow transaction:
>
> begin tran
> insert users (userName,age) values ('mark',25)
> insert users (userName,age) values ('jack',257777777777
7767777)
> commit tran
>
> obviously,the second setence has an overflow error,
> the question is:has the first record been inserted into the users table?
> why?
>
>


Because you told it to. You need error checking (or try/catch in SQL 2005)
to prevent execution from moving from the line that generates the error to
the line that commits the transaction.

David


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com