SQL> create table student
  2  (sno char(9) primary key,
  3  sname char(20) unique,
  4  ssex char(2),
  5  sage smallint,
  6  sdept char(20)
  7  );表已创建。
SQL> create table course
  2  (cno char(4) primary key,
  3  cname char(40),
  4  cpno char(4),
  5  ccredit smallint,
  6  foreign key(cpno) references course(cno)
  7  );表已创建。SQL> create table sc
  2  (sno char(9),
  3  cno char(4),
  4  grade smallint,   
  5  primary key (sno,cno),
  6  foreign key (sno) references student(sno),
  7  foreign key(cno) references course(cno)
  8  );
问题是前2个表都插入数据完成,插入sc时问题;
insert into table sc values('200215121',,92);
这个地方出现错误oracle ora-02291  就是'1'找不到键值,这个表参照了前面2个表的数据,怎么样处理?
还有linux环境下,没有图形界面,连接学校的远程服务器。
希望牛人可以解答,谢谢。
mysql下没问题,但是oracle救出错

解决方案 »

  1.   

    1. insert into table sc values('200215121',,92);是你少寫了第二個值吧
    2. 前面兩個表的插入後,有沒有commit?
      

  2.   

    --建议楼主把字符型改成varchar2类型的 当你插入的记录的长度没有满足4会补空格 会给后面带来麻烦
    insert into table sc values('200215121','1',92); --这里漏了1吧
    你前面的插入提交没 提交在插入
      

  3.   


    Student表中有没有sno为'200215121'的记录
    还有就是第三个表的插入语句中一定要有cno字段,且该字段的值再course表中要存在。
      

  4.   

    insert into table sc values('200215121','1',92);
    另外,看下你course表中是否有cno='1'的记录
      

  5.   

    你好丢了个1
    应该是insert into table sc values('200215121','1',92);
    发帖漏掉了。
    前面的2个表数据都完成了,只是第三个插入加不进去,不知道怎么回事,第三个参照前面2个表的,可是在mysql下就没问题。不知道怎么回事,算了结贴吧,要是知道原因告诉我,谢谢