In my database, I need to store employees, customers, and suppliers. Since all of these share data in common, but are not all data, I have decided to create a pessoas
table 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, such as funcionarios
:
id_pessoa // único, não nulo e chave estrangeira em pessoa(id)
data_admissao
data_demissao
salario
The relationship between funcionarios
and pessoas
must be one-to-one (or none), since a person record can only have an employee, customer, or vendor record.
What I tried to address was an "inheritance." funcionarios
inherits all columns of pessoas
.
I do not know if I made the right decision here. Is this a bad practice? If so, are there other alternatives? Should I repeat all fields from pessoas
to funcionarios
, clientes
and fornecedores
and delete pessoas
?
I must have expressed myself badly because this kind of relationship does not look like one to one, but one to one or zero. Am I right?
Is the pessoas.tipo
column really necessary?