I would like to write a procedure to add multiple parent records with child records in a related table. This is the sort of thing you would do to add multiple Customers in an Customer table and Order items to an CustomerOrder table.
I know the process would be as follows:
- Insert multiple Customers into Customer table using Insert - Select.
- Get the primary key of the each Customer record (presuming it’s auto- numbered)
- Loop: add multiple order records, with the foreign key set to the primary key in step 2 above.
- (Possibly) update the parent invoice parent record with anything derived from the child records (such as a total).
I am inserting records into Customer table using Table type parameter and Customer table has auto increment ID, How can I pass this auto increment customer ids to Order table?