开发者

foreign key of database management System

what is composi开发者_StackOverflowte foreign Key?


If you are referencing a table that has a composite primary key (on composed from more than one column), the foreign key must also have the same columns, hence, a composite foreign key.


'Composite' refers to composing a key out of "multiple" keys. Take this example where table A has composite primary key using two columns (A1, A2). Hence, another table referring to this table will also have a composite foreign key .. in this case (B2, B3).

TABLE A( A1, A2, A3,
  PRIMARY KEY(A1, A2)
)

TABLE B( B1, B2, B3, B4,
  FOREIGN KEY(B2, B3) REFERENCES A(A1, A2)
);


There are compound and composite keys.

Compound keys are keys made out of 2 or more columns. Each of the attributes that make up the compound key are simple keys.

Most of the keys we work with are actually compound keys, not composite keys.

Composite key is a key made out of 2 or more attributes, but each of those attributes is NOT a simple key. Example would be creating a key out of first name and e-mail address - neither are simple keys.

This is nitpicking, and for most purposes we can refer to keys as composite. However, the difference does exist and I thought it should be mentioned.

Composite foreign key would be a key pointing to a record whose referenced keys are not simple keys.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜