How do I enforce uniqueness in a table?

后端 未结 4 875
慢半拍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:58

    You would just get the amount of rows returned from this example query:

    SELECT COUNT(*) FROM enrollment WHERE student_id = 'XYZ' AND subject = 'ABC' AND academic_period = 'DEF'

    If the amount of rows returned is greater than 0, they have already been enrolled in that subject in the academic period.

提交回复
热议问题