Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie question on SCOPE_IDENTITY
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01196646
Message ID:
01196665
Views:
9
>Hi, Dmitry,
>
>I don't immediately see an issue - you're sure that an INSERT was done on that ocnnection, just prior to you calling scope_identity?
>
>This may not answer your specific question, but here's a thought - I noticed you posted this under SQL2005. In 2005, there's an alternative to using scope_identity that (in my opinion) is a bit more efficient. SQL2005 now includes an OUTPUT clause that allows you to get immediate feedback on what's been inserted (or updated). So you could do something like this...
>
>
>DECLARE @tTestTable TABLE ( MainPK  [int] IDENTITY(1,1) NOT NULL,  Name Char(50))
>INSERT @tTestTable OUTPUT Inserted.MainPK  VALUES ('Kevin Goff')
>
>
>That will return the value of the identity columnn that was just inserted.
>
>(Output basically provides visibility to the INSERTED and DELETED system tables, that previously were only visibile in a database trigger)
>
>
>If you have multiple inserts and want to direct them to a temporary area, you can redirect the OUTPUT...
>
>
>DECLARE @tTestTable TABLE ( MainPK  [int] IDENTITY(1,1) NOT NULL,  Name Char(50))
>
>declare @ttemp table (mainpk int)
>INSERT @tTestTable OUTPUT Inserted.MainPK  into  @ttemp VALUES ('Kevin Goff')
>INSERT @tTestTable OUTPUT Inserted.MainPK  into  @ttemp VALUES ('Steve Goff')
>
>select * from @ttemp   -- will give you 1 and 2
>
>
>Again, that doesn't answer your specific question, but now that I have all my clients on SQL2005, I've cut down on scope_identity in favor of this approach.
>
>Kevin

Hi Kevin,

I have not really studied your code. And I don't mind changing my approach to getting the Identity value differently. But I thought that OUTPUT is used with stored procedure. And I insert using SPT method (from VFP).

And my Insert and getting Identity is done on the same connection: I only use one connection for my application.

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform