Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 transaction @@identity ??

Author  Topic 

gpiva
Starting Member

47 Posts

Posted - 2005-01-11 : 20:20:09
Hello I am wondering if is necessary to use begin transaction / commit

to isolate a statement like this one that is contained in a store procedure:

---begin trans???

INSERT INTO Corporate
(CorporateName, CorporateDescription, CorporateCreated, CorporateModified, fk_StatusID)
VALUES (@Name, @Description, @xDate, @xDate, 2)

select @@identity as CorporateID

---commit trans???

any help appreciated.

Carlo

vsanthosaraj
Starting Member

2 Posts

Posted - 2005-01-12 : 03:43:39
For only one insert statment, the begin tran block is not needed!

in case you are inserting or updating more than one table,
and suppose the second line cause error, you can roll back your transaction ie. undo the first statement.

-Victor santhosaraj
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2005-01-12 : 04:45:45
Have a look at "implicit transactions" in BOL.

You might also want to use SCOPE_IDENTITY() instead of @@IDENTITY.
Why?
Have a look at BOL for IDENT_CURRENT. There you'll find an example that explains the differences quite well.

--
Frank
http://www.insidesql.de
Go to Top of Page

gpiva
Starting Member

47 Posts

Posted - 2005-01-12 : 17:31:06
thank you for the info.


Carlo
Go to Top of Page
   

- Advertisement -