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 = @IDRead more about this topic: Identity Column
Famous quotes containing the words related and/or functions:
“So universal and widely related is any transcendent moral greatness, and so nearly identical with greatness everywhere and in every age,as a pyramid contracts the nearer you approach its apex,that, when I look over my commonplace-book of poetry, I find that the best of it is oftenest applicable, in part or wholly, to the case of Captain Brown.”
—Henry David Thoreau (18171862)
“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 (18171862)