Update record's foreign key field based on a newly inserted record's primary key
You can use a cursor to loop through TableA and create the records:
DECLARE @Id int
DECLARE @ForeignKey int
DECLARE C CURSOR FOR SELECT Id FROM TableA
OPEN C
FETCH NEXT FROM C INTO @Id
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO TableB VALUES (value1)
SET @ForeignKey = SCOPE_IDENTITY()
UPDATE TableA
SET ForeignKey = @ForeignKey
WHERE Id = @Id
FETCH NEXT FROM C INTO @Id
END
CLOSE C
DEALLOCATE C