-
[Err] 1822 - Failed to add the foreign key constraint. Missing index for constraint 'sc_num_max_ibfk_1' in the referenced table 'courses':
- 解释:增加外键错误,courses表中cname并不是主码,创建sc_num_max表,其中cname不能设为候选码即外码
- [Err] 1052 - Column 'cid' in group statement is ambiguous
- 解释:字段名与所建表中的不不符
-
--报错1052:错误 create table sc_num_max(cname char(30) primary key ,num_always smallint ,max_score int) insert into sc_num_max(cname,num_always,max_score) select cname,count(cid),max(score) --(cid没有查询) from choices,courses group by cid--(因此不能查询到) --修改后 create table sc_num_max(cname char(30) primary key ,num_always smallint ,max_score int) insert into sc_num_max(cname,num_always,max_score) select cid,count(cid),max(score)--(我将cname直接用cid代替,除非有特殊要求必须查cname再重新该代码) from choices group by cid