在参考表'factIngresosCurso'中没有与参考列匹配的主键或候选键

时间:2018-11-11 14:48:47

标签: sql sql-server foreign-keys

请帮助,我总是收到此消息:

  

在引用表'factIngresosCurso'中没有与外键'fk_ingresos_curso'中的引用列列表匹配的主键或候选键。

我的桌子:

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

1 个答案:

答案 0 :(得分:0)

<color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="bottomText">#6b6b6b</color> <color name="rippleEffectColor">#f916a463</color> 中的主键

factIngresos

在另一个表中,您使用以下列和顺序对其进行引用:

cicCod, curCod, curSec

如您所见,仅从列名中猜测,排序与主键规范中的不同。

您需要确保,该列及其顺序(!!)相同-所以我想,您需要改用以下外键配置:

foreign key(cursec, ciccod, curcod)