Friday, 23 August 2013

How to know the value of the INT sequential I just INSERTed in SQL 2008 R2

How to know the value of the INT sequential I just INSERTed in SQL 2008 R2

I have these tables (simplified for clarity):
TABLE CHANGES
ChangeID bigint
MemberID varchar(10)
ChangedOn smalldatetime
TABLE FIELDCHANGES
ChangeID bigint
FieldName varchar(30)
OldValue varchar(100)
NewValue varchar(100)
In order to keep track of changes made to a Member (MemberID).
What I want to do is INSERT a record in CHANGES, with SQL generating
sequential value (by using IsIdentity) for the ChangeID column and then
INSERT a record in FIELDCHANGES with that value and the other details.
Now, I could INSERT and then SELECT the latest record for that MemberID,
but I was wondering if there was an efficient way to do this, like SQL
returning the value of the ChangeID column when doing that INSERT.

No comments:

Post a Comment