I have a MySQL table that lists delivery records (customerId, date, quantity, productId, cost). I have a requirement to log certain items from the delivery table into a separate table to track items being sent to quarantined areas. All quarantined products must have a serialized tag affixed for tracking with the state.
I assume I will need a stored procedure to loop through the delivery table and insert the correct number of rows into a Log (using auto-increment). For example if there are 5 Product A in a record in delivery, I will need 5 records in the Log one for each logId assigned to that product/customer combination.
I wanted to ask for advice on how to loop (subloop?) through the table and then through each item to get the correct number of rows inserted into the Log table.
The delivery table will look like this:
**deliveryId date customerId Quantity productId cost**
10121 2020-06-01 2250 4 2354 99.99
10122 2020-06-01 2250 2 2433 49.99
The log for those records should look like this:
**tagId customerId productId date **
101765 2250 2354 2020-06-01
101766 2250 2354 2020-06-01
101767 2250 2354 2020-06-01
101768 2250 2354 2020-06-01
101769 2250 2433 2020-06-01
101770 2250 2433 2020-06-01