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:

    So-called “austerity,” the stoic injunction, is the path towards universal destruction. It is the old, the fatal, competitive path. “Pull in your belt” is a slogan closely related to “gird up your loins,” or the guns-butter metaphor.
    Wyndham Lewis (1882–1957)

    The mind is a finer body, and resumes its functions of feeding, digesting, absorbing, excluding, and generating, in a new and ethereal element. Here, in the brain, is all the process of alimentation repeated, in the acquiring, comparing, digesting, and assimilating of experience. Here again is the mystery of generation repeated.
    Ralph Waldo Emerson (1803–1882)