Home All Groups Group Topic Archive Search About

Most basic transaction?

Author
17 Feb 2006 9:14 AM
Lasse Edsvik
Hello

I was wondering if you could show me the most basic transaction in code?

And rollback if error :)

Author
17 Feb 2006 9:33 AM
ML
I suggest you read these articles by Erland Sommarskog:
http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html

There's more to know than you might expect.


ML

---
http://milambda.blogspot.com/
Author
17 Feb 2006 11:53 AM
Razvan Socol
Hi, Lasse

See this excellent article by Erland Sommarskog, SQL Server MVP:
http://www.sommarskog.se/error-handling-II.html#firstexample

Razvan
Author
17 Feb 2006 1:49 PM
Wayne Snyder
Go read the stuff Erland has... but here is a sample

Declare @error int
Delcare @rowcount int
Begin Tran
INsert into yada yada
Select @error = @@error, @rowcount = @@rowcount
If @error !=0 OR @rowcount !=1
   Begin
  Raiserror (yada yada
  Rollback tran
  Return  -999 --if in SP
  End
Commit Tran
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC

I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.


Show quote
"Lasse Edsvik" wrote:

> Hello
>
> I was wondering if you could show me the most basic transaction in code?
>
> And rollback if error :)
>
>
>
>

AddThis Social Bookmark Button