Rick Deckard
Rick Deckard

Reputation: 61

What is the best database schema to connect "students" and "schools"

Using this simplified example; what approach do you think is better and why?

Edit: The relation must be 1 to 1. A student only exists in one school.

Option1

**Table Schools:**
id int primary key;
name string;
**Table students:**
id int primary key;
name string;
idSchool int;

Option2

**Table Schools:**
id int primary key;
name string;
**Table Students:**
id int primary key;
name string;
**Table SchoolsStudents**
idSchool int;
idStudent int;
idSchool, idStudent as primary key;

Upvotes: 1

Views: 205

Answers (1)

TGH
TGH

Reputation: 39278

Option1 one makes sense if a student can only attend one school. Option2 is necessary if a student can attend multiple schools.

Upvotes: 3

Related Questions