外键是否可以引用另一个外键

jos*_*rth 6 sql oracle foreign-keys

是否可以使用引用另一个表中的另一个外键的外键,或者它只能引用主键和唯一键?

Tom*_*att 10

外键可以引用任何定义为唯一的字段.如果该唯一字段本身被定义为外键,则没有区别.外键只是为了强制引用完整性.使字段成为外键不会以任何方式更改字段本身.如果它是一个唯一的字段,它也可以是另一个FK的目标.

例如:

create table Table1(
     PK int identity primary key,
     ...
);
create table Table2( -- 1-1 relationship with Table1
     PKFK int primary key,
     ...,
     constraint FK_Table2_1 foreign key( PKFK ) references Table1( PK )
);
create table Table3( -- relates to Table2
    PKFKFK int primary key,
    ...,
     constraint FK_Table3_2 foreign key( PKFKFK ) references Table2( PKFK )
);
Run Code Online (Sandbox Code Playgroud)

我知道没有DBMS,事实并非如此.我同意马,这种做法没有错.