假设我的数据库中有一个表主题,其数据如下:
subject_nam credit gpa
chemistry 3.00 null
physics 3.00 null
还要假设我有一个学生桌。它将包含基本的学生信息。
现在我需要为每位学生建立一份这些学科的副本,以便建立什么样的关系。每位学生的gpa列会有所不同。
答案 0 :(得分:1)
我将创建一个数据库模型,例如:
create table subject (
id int primary key not null,
name varchar(50) not null,
credits int not null
);
create table student (
id int primary key not null,
name varchar(50) not null
);
create table gpa_score (
subject_id int not null,
student_id int not null,
score int not null,
weighted_score int not null, -- added extra column as requested
constraint pk_gpa primary key (subject_id, student_id),
constraint fk1 foreign key (subject_id) references subject (id),
constraint fk2 foreign key (student_id) references student (id)
);