Checking data integrity for an object

I have three STUDENT, DEPARTMENT AND COURSE tables in the university database ... STUDENT has a UID as a primary key → which is a UNIQUE student ID. DEPARTMENT has Dept_id as a primary key → which is a department number of a COURSE has C_id as a primary key → which is the identifier of the course / object

I need to store labels in a table, linking the primary key of the STUDENT, DEPARTMENT and COURSE for each student in each course.

UID Dept_id C_id marks
1    CS     CS01  98
1    CS     CS02  96
1    ME     ME01  88
1    ME     ME02  90

The problem is that I create a table similar to this one for labels, then I feel that the data operator may insert the wrong combination of student primary key, for example

UID Dept_id C_id marks
1    CS     CS01  98
1    CS     CS02  96
1    ME     CS01  88 //wrong C_id (course id) inputted by the DBA
1    ME     ME02  90

In which case can I stop him from doing this? Is there also a way to keep grades for each student? I mean:

UID Dept_id CS01 CS02
1    CS      98   96
3    CS      95   92
+3
4

, :

UID Dept_id C_id marks
1    CS     CS01  98
     ^^     ^^

:

  • (, ), ( "CS", "01" ).

  • , , course marks. , , JOIN .

. , NULL.

+5

, , . , :

UID C_id marks
1    CS01  98
1    CS02  96
1    ME01  88
1    ME02  90

, , . , , . , , .

+2

. , acment. .

, , ( ) . ( CS89, CS98), . , , , , . , , , .

+1

, , , . , . ; , , .

: 29 1957 ; 15 2025 ; 27 1974 .

0

Source: https://habr.com/ru/post/1754420/


All Articles