Friday, 27 January 2012

Difference in Identity Functions

Small script to demo the usage of different Identites

Create table testIdentity (Id int Identity Primary Key, name varchar(100))

Create Table testIdentityLog (Id int Identity(1000, 1) Primary Key, dt dateTime)

Create Trigger trigtestIdentity on testIdentity
after insert
Insert into testIdentityLog Values (getdate())

Insert into testIdentity Values ('One')
select @@IDENTITY id, SCOPE_IDENTITY() ActualId

Insert into testIdentityLog Values (getdate())
select @@IDENTITY id, SCOPE_IDENTITY() ActualId, IDENT_CURRENT('testIdentity'), IDENT_CURRENT('testIdentityLog')

No comments:

Post a Comment