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相关推荐

  1. [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 ...

  2. Mysql 建立外键出错1822 可能原因之一分析 - Failed to add the foreign key constraint. Missing index for constraint

    项目场景: 通过sql语言在MySQL查询中建立表,其中一个表引用其他表的属性出现问题报错1822 问题描述 被引用的表--用户信息表: 可以看到其中已有主键s_id,为自增长形式 CREATE TA ...

  3. 关于mysql添加外键的时候报错_MySQL添加外键时报错:1215 Cannot add the foreign key constraint的一个可能解决方法...

    今天给设计好的班级表和专业表以及院系表添加外键时,报了这样一个错误 ** 1215 Cannot add the foreign key constraint ** 去百度搜了一圈,说可能时因为字段类 ...

  4. mysql添加外键1215错误_MySQL添加外键时报错:1215 Cannot add the foreign key constraint的解决方法...

    前言 这篇文章主要涉及到在数据创建表时,遇到ERROR 1215 (HY000): Cannot add foreign key constraint 问题方面的内容,对于在数据创建表时,遇到同样问题 ...

  5. 1215-Cannot add the foreign key constraint

    转自:http://blog.csdn.net/blueheart20/article/details/51885947 外键约束过程中碰到的一个问题. 1. 问题的提出 创建两个表: product ...

  6. Error 1215:Cannot add foreign key constraint

    今天用数据库时出现 Error 1215:Cannot add foreign key constraint 报错,在经历了一番波折后解决了问题的所在,写下这篇博客记录一下. 运行的代码: CREAT ...

  7. 数据库六大约束用法:主键(primary key)、外键(foreign key)、非空(not null)、默认(default)、检查(check)、唯一(unique)

    1. 数据库有六大约束 主键(primary key) 外键(foreign key):被参照的键必须有唯一约束或是主键 非空(not null) 默认(default) 检查(check):orac ...

  8. SQL学习之foreign key约束

    目录 参考源 SQL foreign key 约束 FOREIGN KEY 作用 create table 时的 SQL foreign key 约束 MySQL SQL Server / Oracl ...

  9. mysql set foreign key_Mysql 外键(FOREIGN KEY)使用注意事项

    外键,FOREIGN KEY, 这个东东,作为DBA,在Oracle我们都不建议在数据库级别去实现约束,因为他的维护成本很高, 比如你要保证索引,导入数据时你得保证先后顺序等,所以我们更推荐由应用去控 ...

最新文章

  1. 利润中心, 成本中心, 工作中心
  2. synaptic不停抖动后自动关闭的问题
  3. .Net开发人员应该下载的十种必备工具(三)
  4. linux 物理内存用完了_调整linux内核尽量用内存,而不用swap
  5. c 设计计算机报告,C课程设计(计算器)报告
  6. python 数据结构包括三方面_python数据结构
  7. cuzysdk version 3.1 更新说明
  8. webstorm运行的端口在哪看_webstorm(10.0.2)的端口号修改
  9. 运动会管理系统(JAVA,JSP,SERVLET,SQLSERVER)
  10. 计算机系统动态库修复,win10系统提示dll动态链接库出现故障修复的处理步骤
  11. 提供搜题公众号题库接口
  12. 区块链+保险从这些方面落地应用效果显著
  13. [论文阅读] (23)恶意代码作者溯源(去匿名化)经典论文阅读:二进制和源代码对比
  14. SQL中rand和order by rand()用法
  15. 革新科技的TI+ST+XILINX嵌入式异构多核开发平台教育市场应用
  16. hellojs使用 推特登录/api nuxt vue
  17. 北京汽车转型背后:“大北汽”棋局中的变与不变
  18. 谷歌404页面html,简洁404页面HTML好看的404错误页源码
  19. 如何将手机CAJ转换成PDF文件的方法
  20. 在html里如何下雪花,html加动态雪花

热门文章

  1. Java中LinkedList详解
  2. (3)形态学:语言的词汇----NLP的语言学基础
  3. java poi 将公文套红 并 电子签章
  4. [生命科学] 生物基础实验之DNA提取
  5. 还在纠结芯片引脚需要加多大容值的电容吗?
  6. charles+Proxifier实现抓包pc端(exe程序)
  7. ping命令的七种用法总结
  8. 物料编码主文件------(整理)
  9. 你总问,全面发展还是术业专攻?这就是答案
  10. linux系统命令作业