Identity Column - Related Functions

Related Functions

It is often useful or necessary to know what identity value was generated by an INSERT command. Microsoft SQL Server provides several functions to do this: @@IDENTITY provides the last value generated on the current connection in the current scope, while IDENT_CURRENT(tablename) provides the last value generated, regardless of the connection or scope it was created on.

Example:

INSERT INTO Contacts ( FirstName, LastName ) VALUES ( 'Test', 'User' ) -- SELECT @@IDENTITY -- OR -- DECLARE @ID INT SELECT @ID = @@IDENTITY UPDATE Contacts SET Phone = 'XXX-YYY-ZZZZ' WHERE ContactID = @ID

Read more about this topic:  Identity Column

Famous quotes containing the words related and/or functions:

    “Gambling is closely related to theft, and lewdness to murder.”
    —Chinese proverb.

    “Those things which now most engage the attention of men, as politics and the daily routine, are, it is true, vital functions of human society, but should be unconsciously performed, like the corresponding functions of the physical body.”
    —Henry David Thoreau (1817–1862)