Pessoal,
não sei se é uma coisa simples. Porém eu tenho uma tabela que possui um auto relacionamento, e quando tento usar o comando delete ocorre erro de check constraint.
Banco: PostgreSQL
Segue a tabela abaixo:
CREATE TABLE t06_ator
(
identificador serial NOT NULL,
nome character varying(30) NOT NULL,
id_generalizacao integer,
projeto integer NOT NULL,
CONSTRAINT t06_ator_pk PRIMARY KEY (identificador),
CONSTRAINT ator_projeto_fk FOREIGN KEY (projeto)
REFERENCES t01_projeto (codigo) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT id_gen_identificador_fk FOREIGN KEY (id_generalizacao)
REFERENCES t06_ator (identificador) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;
ALTER TABLE t06_ator OWNER TO postgres;
Dados:
Comando executado:
delete from t06_ator where projeto = 1
Erro:
ERROR: update or delete on table “t06_ator” violates foreign key constraint “id_gen_identificador_fk” on table “t06_ator”
Solução:
Procuro algum jeito de realizar o delete em cascata, para não ocorrer o erro de deletar os registros pais antes dos filhos…
Alguem me ajuda ??