See the documentation for SCOPE_IDENTITY.
SCOPE_IDENTITY[
^]
Example
CREATE TABLE [dbo].[T1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[field1] [nchar](10) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[T3](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ID_REF] [int] NOT NULL,
[field1] [nchar](10) NOT NULL
) ON [PRIMARY]
GO
Note: These two SQL statements can be sent to the SQL Server in one command string.
insert into T1 (field1) VALUES('XX');
insert into T3 (ID_REF,field1) VALUES(SCOPE_IDENTITY(),'YY');