Professional Documents
Culture Documents
Identity Column in SQL: Relational Database Concepts
Identity Column in SQL: Relational Database Concepts
IDENTITY Property Identifier columns can be implemented using the IDENTITY property, which allows the application developer to specify both an identity number for the first row inserted into the table (Identity Seed property) and an increment (Identity Increment property) to be added to the seed to determine successive identity numbers. When inserting values into a table with an identifier column, Microsoft SQL Server 2000 automatically generates the next identity value by adding the increment to the seed.
Note: A table can have only one column defined with the IDENTITY property, and that column must be defined using the decimal, int, numeric, smallint, bigint, or tinyint data type.
IDENT_CURRENT Returns the last identity value generated for a specified table in any session and any scope. Syntax IDENT_CURRENT('table_name') IDENT_INCR Returns the increment value (returned as numeric(@@MAXPRECISION,0)) specified during the creation of an identity column in a table or view that has an identity column. Syntax IDENT_INCR ( 'table_or_view' ) IDENT_SEED Returns the seed value (returned as numeric(@@MAXPRECISION,0)) specified during the creation of an identity column in a table or a view that has an identity column. Syntax IDENT_SEED ( 'table_or_view' )
Example script.
CREATE TABLE employees ( Empno int IDENTITY(1,1), fname varchar (20), lname varchar(30), Sex char(1), others.. ) INSERT employees (fname, lname, Sex, Others) VALUES ('Karin', 'Josephs, F, Others)
***
Thank You