Pessoal preciso fazer uma referencia de uma coluna com outra de outra tabela
mas ta me dando erro:
estou tentando assim:

alter table perguntas add CONSTRAINT perguntas_id_pergunta_fkey FOREIGN KEY
(id_pergunta)
      REFERENCES gabaritos (id_pergunta) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE


ERRO: não há restrição de unicidade que corresponde com as colunas
informadas na tabela referenciada "gabaritos"
SQL state: 42830


CREATE TABLE perguntas
(
  id_perg serial NOT NULL,
  id_pergunta integer NOT NULL,
  id_agenda integer NOT NULL,
  CONSTRAINT perguntas_pkey PRIMARY KEY (id_perg)
)

CREATE TABLE gabaritos
(
  id_gabarito serial NOT NULL,
  id_agenda integer NOT NULL,
  id_pergunta integer NOT NULL,
  CONSTRAINT gabaritos_pkey PRIMARY KEY (id_gabarito)
)

A intenção é que quando remover uma pergunta, ele verificar qual é o
id_pergunta da tabela pergunta e também remover os registros da tabela
gabaritos onde id_pergunta possuir o mesmo valor.

Agradeço ajuda
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a