1822 - Failed to add the foreign key constraint. Missing index for constraint ‘fk_tno_course‘ in the
1822 - Failed to add the foreign key constraint. Missing index for constraint ‘fk_tno_course’ in the referenced table ‘teacher’
原因:表A字段a不是作为表A的主键,那么字段a就不能作为表B的外键
原代码
create table student(sno varchar(10) primary key,sname varchar(20),sage NUMERIC(2,0),ssex varchar(5)
);create table teacher(tno varchar(10),tname varchar(20)
);create table course(cno varchar(10) primary key,cname varchar(20),tno varchar(20) not null,constraint fk_tno_course foreign key (tno) references teacher(tno)
);create table score(sno varchar(10),cno varchar(10),score NUMERIC(4,2),constraint pk_sno_cno primary key (sno,cno),constraint fk_cno_score foreign key (cno) references course(cno),constraint fk_sno_score foreign key (sno) references student(sno)
);
改后的代码
create table student(sno varchar(10) primary key,sname varchar(20),sage NUMERIC(2,0),ssex varchar(5)
);create table teacher(tno varchar(10) primary key,tname varchar(20)
);create table course(cno varchar(10) primary key,cname varchar(20),tno varchar(20) not null,constraint fk_tno_course foreign key (tno) references teacher(tno)
);create table score(sno varchar(10),cno varchar(10),score NUMERIC(4,2),constraint pk_sno_cno primary key (sno,cno),constraint fk_cno_score foreign key (cno) references course(cno),constraint fk_sno_score foreign key (sno) references student(sno)
);
1822 - Failed to add the foreign key constraint. Missing index for constraint ‘fk_tno_course‘ in the相关推荐
- [HY000][1822] Failed to add the foreign key constraint. Missing index for constraint ‘fk_com’
[HY000][1822] Failed to add the foreign key constraint. Missing index for constraint 'fk_comment_hnu ...
- Mysql 建立外键出错1822 可能原因之一分析 - Failed to add the foreign key constraint. Missing index for constraint
项目场景: 通过sql语言在MySQL查询中建立表,其中一个表引用其他表的属性出现问题报错1822 问题描述 被引用的表--用户信息表: 可以看到其中已有主键s_id,为自增长形式 CREATE TA ...
- 关于mysql添加外键的时候报错_MySQL添加外键时报错:1215 Cannot add the foreign key constraint的一个可能解决方法...
今天给设计好的班级表和专业表以及院系表添加外键时,报了这样一个错误 ** 1215 Cannot add the foreign key constraint ** 去百度搜了一圈,说可能时因为字段类 ...
- mysql添加外键1215错误_MySQL添加外键时报错:1215 Cannot add the foreign key constraint的解决方法...
前言 这篇文章主要涉及到在数据创建表时,遇到ERROR 1215 (HY000): Cannot add foreign key constraint 问题方面的内容,对于在数据创建表时,遇到同样问题 ...
- 1215-Cannot add the foreign key constraint
转自:http://blog.csdn.net/blueheart20/article/details/51885947 外键约束过程中碰到的一个问题. 1. 问题的提出 创建两个表: product ...
- Error 1215:Cannot add foreign key constraint
今天用数据库时出现 Error 1215:Cannot add foreign key constraint 报错,在经历了一番波折后解决了问题的所在,写下这篇博客记录一下. 运行的代码: CREAT ...
- 数据库六大约束用法:主键(primary key)、外键(foreign key)、非空(not null)、默认(default)、检查(check)、唯一(unique)
1. 数据库有六大约束 主键(primary key) 外键(foreign key):被参照的键必须有唯一约束或是主键 非空(not null) 默认(default) 检查(check):orac ...
- SQL学习之foreign key约束
目录 参考源 SQL foreign key 约束 FOREIGN KEY 作用 create table 时的 SQL foreign key 约束 MySQL SQL Server / Oracl ...
- mysql set foreign key_Mysql 外键(FOREIGN KEY)使用注意事项
外键,FOREIGN KEY, 这个东东,作为DBA,在Oracle我们都不建议在数据库级别去实现约束,因为他的维护成本很高, 比如你要保证索引,导入数据时你得保证先后顺序等,所以我们更推荐由应用去控 ...
最新文章
- 利润中心, 成本中心, 工作中心
- synaptic不停抖动后自动关闭的问题
- .Net开发人员应该下载的十种必备工具(三)
- linux 物理内存用完了_调整linux内核尽量用内存,而不用swap
- c 设计计算机报告,C课程设计(计算器)报告
- python 数据结构包括三方面_python数据结构
- cuzysdk version 3.1 更新说明
- webstorm运行的端口在哪看_webstorm(10.0.2)的端口号修改
- 运动会管理系统(JAVA,JSP,SERVLET,SQLSERVER)
- 计算机系统动态库修复,win10系统提示dll动态链接库出现故障修复的处理步骤
- 提供搜题公众号题库接口
- 区块链+保险从这些方面落地应用效果显著
- [论文阅读] (23)恶意代码作者溯源(去匿名化)经典论文阅读:二进制和源代码对比
- SQL中rand和order by rand()用法
- 革新科技的TI+ST+XILINX嵌入式异构多核开发平台教育市场应用
- hellojs使用 推特登录/api nuxt vue
- 北京汽车转型背后:“大北汽”棋局中的变与不变
- 谷歌404页面html,简洁404页面HTML好看的404错误页源码
- 如何将手机CAJ转换成PDF文件的方法
- 在html里如何下雪花,html加动态雪花