N
N
neronru2016-06-06 10:32:56
PostgreSQL
neronru, 2016-06-06 10:32:56

How best to choose the structure of the database?

In general, there are entities Item, Warehouse. An item is a prototype of an item (the category to which the item belongs, its certain characteristics characteristic of this type of item) + certain characteristics of the item instance itself (well, for example, damage, depletion). Also, some items can be combined into one entry, recording only their number (imagine that there is some container in which this item is placed).
All these items are stored in Warehouses, that is, 1 item - 1 warehouse, and 1 warehouse - a lot of items.
For a more illustrative example, let's say there are two types of items: weapons, resources. A weapon is a unique item that has a damage characteristic that is unique to a unique instance.
Resources are an item that can be pooled by simply recording which resources and how many.
To organize this concept, I have several solutions, I don’t understand which is more correct:
Create a table storage_items (id, storage_id, item_prototype_id, count, damaged), while choosing id as the primary key, and create a partial index (storage_id, item_prototype_id) with the COUNT IS condition NOT NULL.
Divide these items into multiple tables.
Create table storage_items(id,storage_id,item_prototype_id,count) and item_instance_properties(id,items_id,damaged), items_id - reference to id in storage_items The
question is which method is more adequate?
PS I apologize in advance, very stupid question ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-06-06
@sim3x

An adequate way is to learn about normal forms and do according to them. It is
worth starting with this option

Склад:
  предмет
  количество

Предмет:
  тип предмета 
  характеристики

ТипХарактеристики:
   название

Характеристика:
  тип характеристики
  значение

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question