> Pensei em algo tipo:
> CREATE TABLE dependente (
>   cpf_pai bigint not null,
>   cpf_mae bigint not null,
>   nome text not null,
>   tipo integer,
>   primary key(cpf_pai, cpf_mae, nome),
>   foreign key (cpf) references funcionario(cpf)
>   );

Se você colocar dois campos referenciando a mesma tabela (no seu caso,
funcionario) você não terá com forçar a integridade referencial.
Sugiro fazer uma tabela intermediária:

CREATE TABLE dependente_funcionario (
cpf_dependente bigint not null,
cpf_responsavel bigint not null,
primary key (cpf_dependente, cpf_responsavel),
foreign key (cpf_dependente) references dependente(cpf),
foreign key (cpf_responsavel) references funcionario(cpf)
);

Esta tabela faz a "cola" entre a tabela de dependentes e funcionários.

[]s
Flavio Gurgel
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a