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:

    The custard is setting; meanwhile
    I not only have my own history to worry about
    But am forced to fret over insufficient details related to large
    Unfinished concepts that can never bring themselves to the point
    Of being, with or without my help, if any were forthcoming.
    John Ashbery (b. 1927)

    When Western people train the mind, the focus is generally on the left hemisphere of the cortex, which is the portion of the brain that is concerned with words and numbers. We enhance the logical, bounded, linear functions of the mind. In the East, exercises of this sort are for the purpose of getting in tune with the unconscious—to get rid of boundaries, not to create them.
    Edward T. Hall (b. 1914)