What is the best way to enforce a 'subset' relationship with integrity constraints

前端 未结 12 1332
一个人的身影
一个人的身影 2020-12-10 18:11

For example, given 3 tables:

  • gastropod
  • snail
  • slug

and assuming we want to enforce that

  1. every row in \'gastropod\
12条回答
  •  执念已碎
    2020-12-10 18:59

    Foreign key referencing gastropod from slug and snail with a unique index on the foreign key columns enforces rules 2 and 3. Rule 1 is trickier though :-(

    The only way I know of to enforce rule 1 is to write some database code that checks snail and slug for the presence of a row.

    By the way - how do you intend to insert data? Whatever order you do it in, you will break a rule.

提交回复
热议问题