- Identity column
An Identity column is a
column ( also known as a field ) in adatabase table that (1) uniquely identifies every row in the table, and (2) is made up of values generated by the database. This is much like anAutoNumber field inMicrosoft Access or a sequence in Oracle. Because the concept is so important indatabase science , allRDBMS systems implement some type of generated key, although each has its own terminology.An identity column differs from a
primary key in that its values are managed by the server and ( except in rare cases ) can't be modified. In many cases an identity column is used as a primary key, however this is not always the case.Two types of identity columns are available in
SQL Server : incremental ( where the user can set a seed and an increment ) and random ( where the server chooses a random numeric value and ensures that it hasn't already been used ).Code Samples
or
Related Functions
It is often useful or necessary to know what identity value was generated by an
INSERT command.SQL Server provides several functions to do this: @@Identity provides the last value generated on the current connection, while Scope_Identity("tablename") provides the last value generated, regardless of the connection it was created on.Example:
External links
* [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/replsql/repldata_078z.asp MSDN Article "Managing Identity"]
Wikimedia Foundation. 2010.