![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Given the object model, I want to design the database tables. The object model is that school has a list of courses. The following are my 2 approaches. My question is which one is better? Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has the foreign key of table COURSE? Please advise the design principles here. Thanks!! Approach #1: table COURSE has the foreign key of NAME in table SCHOOL ================================================== == CREATE TABLE SCHOOL ( NAME varchar(50) not null, PRINCIPAL varchar(12), PRIMARY KEY(NAME) ); CREATE TABLE COURSE ( NAME varchar(50) not null, SCHOOLNAME varchar(50), FOREIGN KEY(SCHOOLNAME) REFERENCES SCHOOL(NAME), PRIMARY KEY(NAME) ); Approach #2: table SCHOOL has the foreign key of NAME in table COURSE ================================================== CREATE TABLE COURSE ( NAME varchar(50) not null, PRIMARY KEY(NAME) ); CREATE TABLE SCHOOL ( NAME varchar(50) not null, PRINCIPAL varchar(12), PRIMARY KEY(NAME), COURSENAME varchar(50), FOREIGN KEY(COURSENAME) REFERENCES COURSE(NAME), ); |
#3
| |||
| |||
|
|
Given the object model, I want to design the database tables. The object model is that school has a list of courses. The following are my 2 approaches. My question is which one is better? Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has the foreign key of table COURSE? Please advise the design principles here. Thanks!! |
#4
| |||
| |||
|
|
Given the object model, I want to design the database tables. The object model is that school has a list of courses. The following are my 2 approaches. My question is which one is better? Should table COURSE has the foreign key of table SCHOOL? Or table SCHOOL has the foreign key of table COURSE? Please advise the design principles here. Thanks!! |
![]() |
| Thread Tools | |
| Display Modes | |
| |