sql - How to use the output statement and insert multiple values with that id -
i want insert values 2 tables.
the first 1 looks this
recipes
recipeid (unique , ai) recipename method discontinued
the second 1 looks this
ingredientrecipe
recipeuniqid (unique , ai) recipeid (same recipeid in recipes table) ingredientid
i want insert recipename , method. if recipeid gets auto incremented. want insert 3 times ingredient recipeid. working 1 ingredient.
insert recipes (recipename, method, discontinued) output inserted.recipeid, '5' ingredientrecipe( recipeid, ingredientid ) values ('potato , chips', 'potato , chips bake everything', 'false');
so want can add 3 times same recipeid different number ingredientid.
how this? use sql server
edit:
i use asp.net c# , n-tier structure. use sql server database
declare variable , store value of primary key used
declare @id int
insert data receipes
table , use scope_identity
function (see this more)
insert recipes (recipename, method, discontinued) values (....) select @id = scope_identity
repeatedly insert ingredients using value
insert ingredientrecipe(recipeid, ingredientid) values (@id, ...) insert ingredientrecipe(recipeid, ingredientid) values (@id, ...) ...
Comments
Post a Comment