Answer the question
In order to leave comments, you need to log in
How to properly build the table architecture in my case?
There are 2 tables with different attributes (columns).
It is necessary (no matter in what way) that in the end you can get another table of this type:
1. The first attribute is the id of the first table. The second attribute is the id of the second table.
2. Ids of the first and second tables must not be repeated, they must be unique . If id '3' of the first table is written, it should not exist anymore.
3. My catch : The first attribute can be NULL and the second can be NULL. That is, either only the id of the first table is written, or only the second, or both the first and the second.
I can only fulfill either the 1st and 2nd condition or only the 1st and 3rd.
In the first case: We
simply create an intermediate table with foreign keys in 1 attribute for the id of the first table and in 2 attributes for the id of the second table. And we make the attributes unique.
In the second case:
The same thing, just do not make these attributes the primary key and do not set a unique constraint.
But it is clear that the values are not unique.
I hope I have explained in detail. Help, please, how to resolve this?
Answer the question
In order to leave comments, you need to log in
So that id in different tables does not repeat, we need a third, common table, in which there will be an auto-increment field associated with a foreign key in the other two
. But I would think about changing the structure. This situation is illogical for a relational database, and you will have to constantly stumble over it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question