Use SCOPE_IDENTITY () to insert in tblRoleOfStuff in place of StaffId . How:
insert into tblStaff values (@name, @age, @address) insert into tblRoleOfStuff values (scope_identity(), @roleid)
EDIT
Too many comments on this subject, so I want to give an explanation.
If the OP guarantees that he will not use triggers, he can use @@IDENTITY (bad practice), this is enough for his needs, but it is best to use SCOPE_IDENTITY() .
SCOPE_IDENTITY (), for example @@ IDENTITY, will return the last authentication value created in the current session, but it will also limit it to your current scope. In other words, it will return the last identifier value that you explicitly created, and not any identity created by a trigger or user-defined function.
SCOPE_IDENTITY() ensures that you get the identifier from the current operation, and not from another connection or the last processed one.
Why not IDENT_CURRENT ? Because
IDENT_CURRENT is not limited to scope and session; it is limited to the specified table. IDENT_CURRENT returns the identifier value generated for a particular table in any session and in any scope.
Thus, you are doing the last busy, but not the current one. Yes, the OP can also use it, but this is bad practice in this situation (for example, using only @@IDENTITY )
Using OUTPUT really good practice, but more difficult for just one identity. If the OP needs to process more than one line at a time - yes, it needs OUTPUT .