Assume that you have designed the following schema of relations:
COURSES (CID, CNAME)
STUDENTS(SID, SNAME, FAV_CIDS)
However, you can not have a relation with set valued attributes (Did not really understand what was meant by this) and you
need to convert it to a normal form. What is the normal form and the resulting schema?
We are studying SQL at school. Could not really make out which normal form this was in and functional dependencies.
Best Answer
You first need to know what's the relationship between those two entities:
Courses
andStudents
. But, you also need to know the abstraction of those entities into your database schema; we all know that aStudent
could be enrolled in manyCourses
, and aCourse
could contain manyStudents
. The relationship between them are many-to-many.The way to enforce a many-to-many relationship is by creating a table apart that will store as Foreign Keys the
Students
, andCourses
Primary Keys. Both foreign keys will compound the table's primary key. This will gives to you the flexibility to store many courses, and many students.However, check below how the tables should look like:
Courses(CourseId (PK), CourseName)
Students(StudentId (PK), StudentName)
StudentsCourses(StudentId (FK)(PK), CourseId (FK)(PK))