Three level database - foreign keys

前端 未结 2 622
我在风中等你
我在风中等你 2021-01-25 18:05

I have a three level database with the following structure (simplified to only show the primary keys):

Table A: a_id
Table B: a_id, b_id
Table C: a_id, b_id, c_i         


        
2条回答
  •  醉梦人生
    2021-01-25 18:38

    If you already have a foreign key between table B and table A to make sure table B only contains entries that have a value for a_id that exists in table A, then the extra FK between table C and table A on a_id is unnecessary. This requires, of course, that the FK relation between Table B and Table A is encorced, active, and not disabled or circumvented in any way.

    Making the FK link between table C and table B already guarantees that TableC.a_id can only refer to a valid value of a_id (since that's guaranteed in table B through the FK relation between Table B and Table A).

提交回复
热议问题