| Platform: | SQL |
| Task: | Get the last identity value inserted into an identity column in the same scope (i.e., get the primary key of the last inserted record so you can correctly relate child record inserts). |
| Discussion: | A good overview of SCOPE_IDENTITY is at http://msdn.microsoft.com/en-us/library/ms190315.aspx |
| Example: | insert into tblParents(Parentname) values ('PJ');
SELECT @@IDENTITY AS [@@IDENTITY]
select * from tblparents where parentid = @@identity; |