How are ER subtypes modeled in a database?

Sorry if this is too easy, but lately I have found a lot of documentation on ER-modeling, but all this seems to skip the actual implementation, and I just want to clarify.

Is only the second table with a foreign key for the supertype, along with the properties related to the subtype, a subtype? In any case, it will be of great value to me. Will the primary subtype key also be shared with the supertype (will the primary subtype have an external supertype restriction)?

+4
source share
1 answer

Yes, this is one of three ways to do this.

The second method, and perhaps the simplest one, is simply to have values ​​in the subtypes in the fields of the supertype, which can be zero. More space is required, but it increases performance because fewer queries are required to obtain subtype-specific data.

The third way is to have a table for each type / subtype. This is only effective if you always know the type / subtype of the data you need to look for. It also does not require as much space as a second.

+3
source

Source: https://habr.com/ru/post/1286601/


All Articles