sql server 中创建外键遇到问题,显示引用的表无效
具体问题要求建立“成绩登记表cjdj”包括学号xh,程号kch,成绩,要求建立主键及与student及kc表联接的外键
--课程kc
create table kc
( kch char(20) primary key,
kcmc char(15),
xxke char(15),
xf int
)
--学生表建立
create table student
(
xh char(12) primary key,
xm char(10),
xb char(2) check(xb='男'),
nl int check(nl>10)
)
--成绩登记表cjdj
create table cidj
( xh char(12) ,
kch char(20),
cj int,
primary key(xh,kch),
foreign key(kch) references kc (kch),
foreign key(xh) references student (xh),
)
成绩登记表cjdj执行时遇到的问题:
消息 1767,级别 16,状态 0,第 2 行
外键 'FK__cidj__kch__52593CB8' 引用了无效的表 'kc'。
消息 1750,级别 16,状态 1,第 2 行
无法创建约束或索引。请参阅前面的错误。