Maison > Article > base de données > Comment créer trois tables relationnelles dans MySQL
create table tbl_stu ( id int not null primary key auto_increment, name varchar(45) not null )engine=innodb default charset=utf8;
create table tbl_sub ( id int not null primary key auto_increment, subject varchar(45) not null )engine=innodb default charset=utf8;
create table tbl_scores( id int not null primary key auto_increment, stu_id int, sub_id int score decimal(5,2), constraint sco_stu foreign key(stu_id) references tbl_stu(id), constraint sco_sub foreign key(sub_id) references tbl_sub(id) );
7. Classement des scores totaux
insert into tbl_stu values (0,"小王"); insert into tbl_stu values (0,"小宋"); insert into tbl_stu values (0,"小李"); insert into tbl_sub values (0,"语文"); insert into tbl_sub values (0,"数学"); insert into tbl_sub values (0,"英语"); insert into tbl_scores values (0,1,1,90); insert into tbl_scores values (0,1,2,70); insert into tbl_scores values (0,1,3,82); insert into tbl_scores values (0,2,1,95); insert into tbl_scores values (0,2,2,70); insert into tbl_scores values (0,2,3,84); insert into tbl_scores values (0,3,1,85); insert into tbl_scores values (0,3,2,86);
.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!