I have a table in Oracle SQL, and a field, I want it to be a foreign key of the same table, but Oracle gives me an error.
create table Empleado_almacen
(
cod_empleado_almacen int,
dni varchar2(9),
dni_jefe varchar2(9),
nombre varchar2(30),
direccion varchar2(50),
sueldo number(4,1),
telefono number(9),
cod_almacen int,
constraint pk_empleado_almacen primary key(cod_empleado_almacen),
constraint fk_empleado_almacen_jefe foreign key (dni_jefe)
references Empleado_almacen(dni_jefe)
on delete cascade,
constraint fk_almacen_empleado_almacen foreign key (cod_almacen)
references Almacen(cod_almacen)
on delete cascade
);
I do not know if the error is exactly on the foreign key, I think so, I write you the error too:
Informe de error -
Error SQL: ORA-02270: no hay ninguna clave única o primaria correspondiente
para esta lista de columnas
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view