I have a 'product' database for storing product details. For each product, it may optionally have 0 - 10 spare parts, with their names accepted through a dynamic form.
I'm unsure how the database-schema should be. From this thread, I got some ideas and this what I came up with.
__________________________________
|products |
|********* |
|id, name, address |
|__________________________________|
__________________________________
|spareparts |
|********* |
|id, name |
|__________________________________|
__________________________________
|products_spareparts |
|********* |
|id, product_id, sparepartid |
|__________________________________|
So my idea is to have 10 rows in the 'spareparts' table since there will not be more than 10 spare parts for a product. Each row will have an ID, and the name field where the names accepted from the form will be stored.
When products are created, if there is a spare part, for each spare part it's name will be added to the 'spareparts' table, product_id and sparepart_id will hold the id of the product and the sparepart respectively.
The spare parts are created on a per-product basis. It's name is accepted from a form and two products may or may not have the same spare parts.
Would this work? Are there better ways to implement it?