How do I enforce uniqueness in a table?

后端 未结 4 898
慢半拍i
慢半拍i 2020-12-21 11:03

For example, I have to program an enrolment table which has:

  1. enrolment_id
  2. academic_period
  3. results
  4. student_id
  5. subject
  6. <
4条回答
  •  渐次进展
    2020-12-21 11:40

    Create a unique constraint on academic_period, student_id, subject
    I'll let you work out the actual SQL

    Note: this is correctly your natural key: enrolment_id is a surrogate added at implementation time because of the database architecture. It isn't mandated in any design or modelling process

提交回复
热议问题