Calling stored procedure from another stored procedure SQL Server

后端 未结 3 602
予麋鹿
予麋鹿 2020-12-14 00:32

I have 3 insert stored procedures each SP inserts data in 2 different tables

Table 1          Table 2                
idPerson         idProduct                      


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 00:49

    Simply call test2 from test1 like:

    EXEC test2 @newId, @prod, @desc;
    

    Make sure to get @id using SCOPE_IDENTITY(), which gets the last identity value inserted into an identity column in the same scope:

    SELECT @newId = SCOPE_IDENTITY()
    

提交回复
热议问题