I will explain problem with an example:
There is two table in my database, named entry, tags
There is a column named ID_ENTRY in both table. When I add a record to table, entry, I have to take the ID_ENTRY of last added record and add it to table, tags. How can I do it?
Immediatly after executing the insert statement on first table, you should query @@IDENTITY doing ‘SELECT @@identity’. That will retrieve the last autogenerated ID… and then just insert it on the second table.
If you are using triggers or something that inserts rows… this may be not work. Use Scope_Identity() instead of @@IDENTITY