如何在表格中强制执行唯一性?

编程入门 行业动态 更新时间:2024-10-20 16:41:48
本文介绍了如何在表格中强制执行唯一性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

例如,我必须编写一个具有以下内容的注册表:

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

  • enrollment_id
  • academic_period
  • 结果
  • student_id
  • 主题
  • 我想强制执行一项操作,以确保学生在特定学期内不能多次注册该科目. 因此,约束条件应包括学生ID",学科"和学期"列.

    I want to enforce to make sure that a student can't enroll in a subject more than once in a specific academic period. So, the constraint shall involve student_id, subject, and academic period columns.

    我仍然不确定如何做到这一点.有帮助吗?

    I'm still unsure how do I make this happen. Any help?

    推荐答案

    向表中添加唯一约束:

    ALTER TABLE yourtable ADD CONSTRAINT constraintname UNIQUE (student_id, subject, academic_period)

    更多推荐

    如何在表格中强制执行唯一性?

    本文发布于:2023-10-14 22:07:39,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1492353.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:强制执行   表格   如何在   唯一性

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!