Table structure with polymorphy

Asked

Viewed 17 times

1

I am developing a CRM and I am in doubt in the structure of the tables, I do not know exactly what is the best way to follow to not have performance problems and also not mix the data, I ended up arriving in 3 options.

Option 1: Use a centralized table with the columns in common between the entities and use two other auxiliaries to complement the data, follow the diagram:

inserir a descrição da imagem aqui

Option 2: Use an individual table for each entity and perform polymorphy in the telephone, address, e-mail tables, follow the diagram:

inserir a descrição da imagem aqui

Option 3: Use a single table for both and all fields are optional, include an is_organization flag to differentiate the two entities, follow the diagram:

inserir a descrição da imagem aqui

Which way would you go?

Complementing: There was an error in the third example, the address table should not exist, it only appears in the second example only to avoid redundant columns, it should be 1:1

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.