R
R
Roman2018-08-08 10:29:51
PostgreSQL
Roman, 2018-08-08 10:29:51

What is the best way to design a one-to-many relationship in this case?

Good day.
I have a task to create a database project. There are about two dozen tables in the database that describe storage objects with different characteristics. It is impossible to combine tables into one, since they are heterogeneous in terms of stored data. But there is a need to search through all tables at once relative to one table. This table indicates the storage location of objects (relatively speaking: a certain shelf in a certain corner of the warehouse). I would like to ask a query on this table and understand if there is something on this shelf and what exactly.
In my opinion, there are several solutions. Or create an additional table where all fields are foreign keys to tables with storage objects and a storage location. Or, in the table of storage locations, specify the id of objects and their types for further processing by logic and search in the corresponding tables.
Please help with advice on how best to do it and whether there is a better solution to this problem. It’s reluctant to store twenty NULLs in the case of foreign keys, but you also don’t want to pull additional queries.
On postgres.
Thanks for answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ApeCoder, 2018-08-08
@ApeCoder

It is impossible to combine tables into one, since they are heterogeneous in terms of stored data.
Combine the general into a separate table
If there are few tables, you can make a query with UNIONs

B
BarryHAllen, 2018-08-08
@BarryHAllen

If I understand the question correctly, you can make a VIEW in which you will collect the information necessary for searching from the plates. You don’t have to change the structure of the database, and you will perform the search by view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question