外键引用了无效的表是什么意思啊?
CREATETableTeachers(Tnochar(7)primarykey,Tnamechar(10)notnull,Sexchar(2)check(Sex='男'...
CREATE Table Teachers
(
Tno char(7) primary key,
Tname char(10) not null,
Sex char(2) check (Sex = '男' or Sex = '女'),
Birthday Date,
Title char(6),
Dno char(4),
foreign key(Dno) references Departments(Dno)
);
CREATE Table SC
(
Sno char(9),
Cno char(5),
Grade smallint check(Grade >= 0 AND Grade <= 100),
primary key(Sno, Cno),
foreign key(Sno) references Students(Sno),
foreign key(Cno) references Cources(Cno)
);
CREATE Table Departments
(
Dno char(4) primary key,
Dname char(10),
Dheadno char(7),
foreign key(Dheadno) references Teachers(Tno)
);
CREATE Table Students
(
Sno char(9) primary key,
Sname char(10) not null,
Sex char(2) check (Sex = '男' OR Sex = '女'),
Birthday Date,
Enrollyear char(4),
Speciality char(20),
Dno char(3),
foreign key(Dno) references Departments(Dno)
);
CREATE Table Cources
(
Cno char(5) primary key,
Cname char(20) not null,
Perid smallint,
Credit smallint
);
CREATE Table Teaches
(
Tno char(7),
Cno char(5),
TCscore smallint,
primary key(Tno, Cno),
foreign key(Tno) references Teachers(Tno),
foreign key(Cno) references Courses(Cno)
);
上面的程序运行后的提示消息是:
消息 1767,级别 16,状态 0,第 1 行
外键 'FK__Teachers__Dno__282DF8C2' 引用了无效的表 'Departments'。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
这是为什么啊? 展开
(
Tno char(7) primary key,
Tname char(10) not null,
Sex char(2) check (Sex = '男' or Sex = '女'),
Birthday Date,
Title char(6),
Dno char(4),
foreign key(Dno) references Departments(Dno)
);
CREATE Table SC
(
Sno char(9),
Cno char(5),
Grade smallint check(Grade >= 0 AND Grade <= 100),
primary key(Sno, Cno),
foreign key(Sno) references Students(Sno),
foreign key(Cno) references Cources(Cno)
);
CREATE Table Departments
(
Dno char(4) primary key,
Dname char(10),
Dheadno char(7),
foreign key(Dheadno) references Teachers(Tno)
);
CREATE Table Students
(
Sno char(9) primary key,
Sname char(10) not null,
Sex char(2) check (Sex = '男' OR Sex = '女'),
Birthday Date,
Enrollyear char(4),
Speciality char(20),
Dno char(3),
foreign key(Dno) references Departments(Dno)
);
CREATE Table Cources
(
Cno char(5) primary key,
Cname char(20) not null,
Perid smallint,
Credit smallint
);
CREATE Table Teaches
(
Tno char(7),
Cno char(5),
TCscore smallint,
primary key(Tno, Cno),
foreign key(Tno) references Teachers(Tno),
foreign key(Cno) references Courses(Cno)
);
上面的程序运行后的提示消息是:
消息 1767,级别 16,状态 0,第 1 行
外键 'FK__Teachers__Dno__282DF8C2' 引用了无效的表 'Departments'。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
这是为什么啊? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |