开发者

if I have a complex primary key, is it possible to create foreign key only for one column of it?

I have this:

ID1 INTEGER 开发者_JAVA百科PRI
ID2 INTEGER PRI
NAME VARCHAR

now I need to:

ID1_REF INTEGER REFERENCE TO ID1
DESCRIPTION VARCHAR

so, one column refers to one column of primary key, not to 2 column. Is it even possible in relational databases?


No you can't. The foreign key must reference either the primary key or another superkey (a set of attributes/columns that uniquely identifies the row in that table, whether or not that is the actual declared primary key) in the referenced table. It's worth reading the Wikipedia article as well.


Technically you can do anything you want. But theoretically this breaks the main concept of primary and foreign keys. Actually it's just a question of terms. I am not sure if the key in your example can be called a foreign key. Maybe we can call it a partial foreign key or something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜