INSERT Statements...

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 лет назад
Hello @ all,

I just noticed, that the INSERT Statements in the Database all return the @@identity parameter, that is (supposed) to contain the PK of the just added record set. This is true as far as it goes, as the @@identity parameter contains the PK of the latest insert statement, which can also be the PK of a record-set in another table. A safer (and recommended way) is to use SCOPE_IDENTITY(), which will definitely contain the desired PK.

Cheers,
hoppi
15 лет назад
hoppi wrote:
Hello @ all,

I just noticed, that the INSERT Statements in the Database all return the @@identity parameter, that is (supposed) to contain the PK of the just added record set. This is true as far as it goes, as the @@identity parameter contains the PK of the latest insert statement, which can also be the PK of a record-set in another table. A safer (and recommended way) is to use SCOPE_IDENTITY(), which will definitely contain the desired PK.

Cheers,
hoppi


Hi all,

I agree with hoppi as SCOPE_IDENTITY() is a much safer statement because it get's the last inserted ID in the current scope. You can read more abt this at: http://msdn.microsoft.com/en-us/library/ms190315.aspx
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.