Oracle referential constraint
Can I have a foreign key with fewer number of columns of the primary/unique keys which it is referencing? (ORA-02270 error says no) 开发者_开发知识库
You can use fewer columns, but the columns you do use have to have a UNIQUE constraint on them.
And, of course, if you can put a UNIQUE constraint on just part of the primary key, then you have to ask yourself a question: "Why does my primary key have more columns than it needs in the first place?"
A FK isn't necessarily the PK of the other table. It can be, but it doesn't have to.
So you can use as FK as many columns as you need...
From oracle:
The foreign key in the child table will generally reference a primary key in the parent table.
Edit: the original question was about number of columns, not about using the incomplete PK as a FK.
The FK must reference something that is unique in the other table. So, you'll have to use any column that have a UNIQUE constraint, or the PK of the other table (since the PK must also be unique. For example, you select multiple columns from the table because each column, alone, is not unique, but the concatenation of multiple columns will be unique).
精彩评论