3
In my database I need to store employees, customers and suppliers. Since all these share data in common, but not all the data, I decided to create a table pessoas
with the columns in common:
id // chave primária
tipo // tipo F para funcionário, C para cliente e F para fornecedor
nome
data_nascimento
endereco
inativo
And to store the specific data of each type I made other tables, as the funcionarios
:
id_pessoa // único, não nulo e chave estrangeira em pessoa(id)
data_admissao
data_demissao
salario
The relationship between funcionarios
and pessoas
should be from one to one (or none), since a person record may only have an employee, customer or supplier record.
What I tried to address was an "inheritance". funcionarios
inherits all the columns of pessoas
.
I don’t know if I made the right decision here. Is this a bad practice? If it is, are there any other alternatives? I should repeat all the fields of pessoas
in funcionarios
, clientes
and fornecedores
and eliminate pessoas
?
I must have expressed myself badly because this type of relationship does not seem one for one and one for one or zero. I’m right?
The column pessoas.tipo
is really necessary?
Related: It can be considered a bad modeling practice to store all people (customers, employees, suppliers) in the same table?
– Oralista de Sistemas