呵呵,FK是foreign key的缩写吧?
偶们公司的几个项目(电信)中是没有用foreign key的,基本上在应用层维护完整性和移植性;
Primary Key:一个表只能有一个PK,对应的一个字段和几个字段在该表中是唯一的unique,且不能为null,这是与unique index的区别,另外PK和FK在数据库中一般都是constraints,与index并列,但在ORACLE和SYBASE等数据库中PK与unique index实现机制是一样的.

解决方案 »

  1.   

    它主要是为了约束数据的完整性。CREATE TABLE s(s# int not null primary key,s_name varchar(8) not null);CREATE TABLE c (c# int not null primary key,c_name varchar(8) not null);CREATE TABLE cs(c# int not null,s# int not null,cj tinyint not null,
    primary key (c#,s#),foreign key(s#) references s(s#),foreign key(c#) references c(c#))insert into s values(1,'saa');
    insert into c values(1,'caa');--这句是对的
    insert into cs values(1,1,86);--这句是错的,sql会报错,应为s表的s#列里没有2
    insert into cs values(2,1,45);