Assuming I have a table items
with columns id, code
.
In my scenario, I am saving 10 items to it:
insert into items (code)
select code
from other_table
where condition
How do I then insert into table itemDescription
(id, item_id, code
) where item_id
would be populated by the previously inserted item id as foreign key?
Insert into itemDescription (item_id, code)
select <foreignkey goes here>, info.data
from items
join info on items.id = info.item_id
where code = "C"
I know there are things like scope identity for retrieving last inserted id, but this is for individual inserts; how does that work if I'm inserting in this way all at once? Is there a way to make this work?
Typically I do a while(1=1) loop or cursor over the items, but am told this isn't "the sql way of doing things"