In my PostgreSQL database, I need to define the following data structure. There will be a table of item
, and it has an auto-incremental column item_id and other item specifications. When a new item is entered, the item_id will be incremented by 1. This is for a parent item.
There will also be child items which have the same item specifications and their unuqie item_id. Multiple child items can be associated with a parent item. The first child's item_id is defined as {parent_item_id}.1 and the second child is {parent_item_id}.2, so on and so forth.
A parent item can be associated with multiple child items hence forming a "one-to-many" relationship.
pseudo Parent Item
item_id, item_name, attribute1, attribute2... attributeN
1, item_name1, attribute, attribute, ..., attributeN
2, item_name2, attribute, attribute, ..., attributeN
3, item_name3, attribute, attribute, ..., attributeN
Please note item_id for only the parent items needs auto-incrementing by 1.
pseudo Child Item
item_id, item_name, attribute1, attribute2... attributeN
1.1, item_name, attribute, attribute, ..., attributeN
1.2, item_name, attribute, attribute, ..., attributeN
1.3, item_name, attribute, attribute, ..., attributeN
2.1, item_name, attribute, attribute, ..., attributeN
2.2, item_name, attribute, attribute, ..., attributeN
3.1, item_name, attribute, attribute, ..., attributeN
What is a best practise to structure the data? Is it a good choice to make two separate tables for parent and child, plus a relationship table?; or make parent and child in one single table?