One interesting thing:
drop table testIdentity
go
create table testIdentity
(
id int identity
)
insert into testIdentity default values
select scope_identity()
begin transaction
insert into testIdentity default values
select scope_identity()
rollback transaction
select * from testIdentity
select scope_identity()
The value returned by scope_identity() is unaffected by the rollback
transaction. Just a little warning, unless I am missing something :)
--
----------------------------------------------------------------------------
Louis Davidson - ***@hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
Post by Dan GuzmanPost by MattCShould I still encapsulate within a Transaction?
The returned identity value will be the same with or without the
transaction.
--
Hope this helps.
Dan Guzman
SQL Server MVP
Post by MattCShould I still encapsulate within a Transaction?
Post by Dan GuzmanYes, it's better to use SCOPE_IDENTITY() in SQL 2000 so that the value
is not affected by triggers.
--
Hope this helps.
Dan Guzman
SQL Server MVP
Post by MattCHi,
BEGIN TRANSACTION
INSERT ......
COMMIT TRANSACTION
INSERT ...
SELECT SCOPE_IDENTITY()
TIA
MattC