I have the following (fictitious) tables:
╔════════════════════╗ ╔════════════════════╗
║ Course ║ ║ Person ║
╠══════╦═════════════╣ ╠══════╦═════════════╣
║ ID ║ int ║ ║ ID ║ int ║
║ Name ║ varchar(50) ║ ║ Name ║ varchar(50) ║
╚══════╩═════════════╝ ╚══════╩═════════════╝
╔════════════════════╗ ╔═════════════════════╗
║ Occupation ║ ║ B_Occupation_Person ║
╠══════╦═════════════╣ ╠══════════════╦══════╣
║ ID ║ int ║ ║ Person_ID ║ int ║
║ Name ║ varchar(50) ║ ║ Ocupation_ID ║ int ║
╚══════╩═════════════╝ ╚══════════════╩══════╝
╔═════════════════╗
║ B_Course_Person ║
╠═══════════╦═════╣
║ Course_ID ║ int ║
║ Person_ID ║ int ║
╚═══════════╩═════╝
In the Occupation
table, there are 2 rows: Student
and Teacher
.
The B_Occupation_Person
binding table allows me to give all the persons an occupation and the B_Course_Person
binding table allows me to associate a teacher with a course.
My problem is I'd like to ensure that B_Course_Person
could only contain teachers.
My first idea was to add a check constraint on this table but I can only do it by using a UDF to get the person's occupation from the B_Occupation_Person
table. And from what I read here, it's bad to use a UDF in a check constraint.
My second idea was to add a column Occupation
in the B_Course_Person
table but then I get data redundancy...
What's the best way, here?
Thanks,