数据库里foreign key......是什么意思
怎么用啊

解决方案 »

  1.   

    是个外键约束,在多表之间
    例如:
    create table info
    (
    id int primary key,
    name varchar2(30)
    );create table score
    ( id int,
    math int),
    foreign key (id) references info (id)
    );录入数据时只能先录入主键表,删除数据时只能先删除外键表
    insert into info values (1,'a');
    insert into info values (2,'b');
    insert into info values (3,'c');
    insert into score values (1,99);
    insert into score values (2,97);
    以上录入数据OK
    insert into score values (4,99); 
    录入这条数据出现错误,因为info表中没有ID=4的记录,所以报错。这样说明白么
      

  2.   

    create table score
    ( id int,
    math int)
    foreign key (id) references info (id)
    );多了个括号,请删除