-2

Help please, I'm always getting this message:

There are no primary or candidate keys in the referenced table 'factIngresosCurso' that match the referencing column list in the foreign key 'fk_ingresos_curso'.

My tables:

create table factIngresos
(
    cicCod char(6),
    curcod char(5) references dimCurso,
    cursec char(2),
    codSec char(1) references dimSeccion,
    tiempoid int references dimTiempo,
    codHor int references dimHorario,
    proCodUno char(5) references dimPersonal,
    vacantes int,
    inscritos int,
    ingresoProyectado money,
    ingresoNeto money,
    becas money default 0,
    constraint pk_Ingresos primary key(cicCod, curCod, curSec) 
)
go

create table factIngCursoAlumno
(
    alucod char(8) references dimAlumno,
    cursec char(2), ciccod char(6), curcod char(5),
    alucurCosto float, alucurefe float,
    alucurPF float,
    constraint pk_facIC primary key(alucod, cursec, ciccod, curcod),
    constraint fk_ingresos_curso 
        foreign key(cursec, ciccod, curcod) references factIngresos(cursec, ciccod, curcod)
)
go
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Your foreign key is referencing `factIngresosCurso`, which is not defined in the question. Hence there is not enough information. – Gordon Linoff Nov 11 '18 at 14:51
  • Possible duplicate of [There are no primary or candidate keys in the referenced table that match the referencing column list in the foreign key](https://stackoverflow.com/questions/17879735/there-are-no-primary-or-candidate-keys-in-the-referenced-table-that-match-the-re) – philipxy Nov 11 '18 at 19:28
  • This is a faq. Please always google many clear, concise & specific versions/phrasings of your question/problem/goal with & without your particular strings/names & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using 1 variant search as title & keywords for tags. See the downvote arrow mouseover text. When you do have a non-duplicate code question to post please read & act on [mcve]. – philipxy Nov 11 '18 at 19:29

1 Answers1

0

The primary key in factIngresos is

cicCod, curCod, curSec

Yet in your other table, you reference it using these columns and sequence:

foreign key(cursec, ciccod, curcod)

As you can see, just guessing from the names of the columns, the ordering is not the same as in the primary key specification.

You need to ensure that the column and their ordering (!!) is identical - so my guess is, you would need to use this foreign key configuration instead:

constraint fk_ingresos_curso 
    foreign key(ciccod, curcod, cursec) references factIngresos(ciccod, curcod, cursec)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459