日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MYsql建立学生成绩表

發布時間:2023/12/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MYsql建立学生成绩表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mysql> show databases;mysql> create database gradesystem;mysql> use gradesystem;mysql> create table tb_class-> (-> clid int not null comment '班級編號',-> clname varchar(20) not null comment '班級名稱',-> primary key(clid)-> );mysql> show tables; +-----------------------+ | Tables_in_gradesystem | +-----------------------+ | tb_class | +-----------------------+mysql> create table tb_student-> (-> stuid int not null,-> stuname varchar(4) not null,-> clid int not null comment '班級編號',-> primary key(stuid)-> );mysql> show tables; +-----------------------+ | Tables_in_gradesystem | +-----------------------+ | tb_class | | tb_student | +-----------------------+mysql> create table tb_course-> (-> cid int not null comment '課程編號',-> cname varchar(20) not null comment '課程名稱',-> primary key (cid)-> );mysql> show tables; +-----------------------+ | Tables_in_gradesystem | +-----------------------+ | tb_class | | tb_course | | tb_student | +-----------------------+mysql> create table tb_mark(-> mid int not null,-> clid int not null comment '班級編號',-> stuid int not null,-> cid int not null comment '課程編號',-> score decimal(4,1) comment '成績',-> primary key(mid)-> );mysql> show tables; +-----------------------+ | Tables_in_gradesystem | +-----------------------+ | tb_class | | tb_course | | tb_mark | | tb_student | +-----------------------+//ALTER TABLE <數據表名> add constraint FK_主表_從表 foreign key (外鍵字段) references 主表(主表主鍵字段); //ALTER TABLE <數據表名> ADD CONSTRAINT <唯一約束名> UNIQUE(<列名>);mysql> alter table tb_student add constraint uni_id unique(stuid);mysql> alter table tb_student add constraint fk_student_clid foreign key(clid) references tb_class(clid);mysql> alter table tb_mark add constraint fk_mark_clid foreign key(clid) referen ces tb_class(clid);mysql> alter table tb_mark add constraint fk_mark_stuid foreign key(stuid) refer ences tb_student(stuid);mysql> alter table tb_mark add constraint fk_mark_cid foreign key(cid) reference s tb_course(cid);mysql> insert into tb_course(cid,cname)values-> (1,'C++程序設計'),-> (2,'多媒體技術'),-> (3,'大學英語'),-> (4,'高等數學'),-> (5,'大學體育'),-> (6,'馬克思主義政治經濟學');mysql> insert into tb_class(clid,clname)values-> (1,'一班'),-> (2,'二班'),-> (3,'三班'),-> (4,'四班'),-> (5,'五班'),-> (6,'六班'),-> (7,'七班'),-> (8,'八班'),-> (9,'九班'),-> (10,'十班');mysql> insert into tb_student(stuid,stuname,clid)values-> (001,'張三',1),-> (002,'李四',1),-> (003,'王二',1);//如果該字段不是主鍵,需要先設置該字段為主鍵://alter table 表名 add primary key(字段名);//修改字段為自動增長//alter table 表名 change 字段名 字段名 字段類型 auto_increment;mysql> alter table tb_mark change mid mid int not null auto_increment;mysql> insert into tb_mark(clid,stuid,cid,score)values-> (1,001,1,80),-> (1,001,2,88),-> (1,001,3,71),-> (1,001,4,60),-> (1,001,5,66),-> (1,001,6,91),-> (1,002,1,77),-> (1,002,2,73),-> (1,002,3,84),-> (1,002,4,93),-> (1,002,5,64),-> (1,002,6,91),-> (1,003,1,97),-> (1,003,2,89),-> (1,003,3,81),-> (1,003,4,79),-> (1,003,5,93),-> (1,003,6,88);mysql> show tables; +-----------------------+ | Tables_in_gradesystem | +-----------------------+ | tb_class | | tb_course | | tb_mark | | tb_student | +-----------------------+mysql> select * from tb_class; +------+--------+ | clid | clname | +------+--------+ | 1 | 一班 | | 2 | 二班 | | 3 | 三班 | | 4 | 四班 | | 5 | 五班 | | 6 | 六班 | | 7 | 七班 | | 8 | 八班 | | 9 | 九班 | | 10 | 十班 | +------+--------+mysql> select * from tb_course; +-----+--------------------------------+ | cid | cname | +-----+--------------------------------+ | 1 | C++程序設計 | | 2 | 多媒體技術 | | 3 | 大學英語 | | 4 | 高等數學 | | 5 | 大學體育 | | 6 | 馬克思主義政治經濟學 | +-----+--------------------------------+mysql> select *from tb_mark; +-----+------+-------+-----+-------+ | mid | clid | stuid | cid | score | +-----+------+-------+-----+-------+ | 2 | 1 | 1 | 1 | 80.0 | | 3 | 1 | 1 | 2 | 88.0 | | 4 | 1 | 1 | 3 | 71.0 | | 5 | 1 | 1 | 4 | 60.0 | | 6 | 1 | 1 | 5 | 66.0 | | 7 | 1 | 1 | 6 | 91.0 | | 8 | 1 | 2 | 1 | 77.0 | | 9 | 1 | 2 | 2 | 73.0 | | 10 | 1 | 2 | 3 | 84.0 | | 11 | 1 | 2 | 4 | 93.0 | | 12 | 1 | 2 | 5 | 64.0 | | 13 | 1 | 2 | 6 | 91.0 | | 14 | 1 | 3 | 1 | 97.0 | | 15 | 1 | 3 | 2 | 89.0 | | 16 | 1 | 3 | 3 | 81.0 | | 17 | 1 | 3 | 4 | 79.0 | | 18 | 1 | 3 | 5 | 93.0 | | 19 | 1 | 3 | 6 | 88.0 | +-----+------+-------+-----+-------+mysql> select * from tb_student; +-------+---------+------+ | stuid | stuname | clid | +-------+---------+------+ | 1 | 張三 | 1 | | 2 | 李四 | 1 | | 3 | 王二 | 1 | +-------+---------+------+mysql> select tb_student.stuname,tb_mark.score,tb_mark.cid from tb_student,tb_mark where tb_student.stuid=tb_mark.stuid; +---------+-------+-----+ | stuname | score | cid | +---------+-------+-----+ | 張三 | 80.0 | 1 | | 張三 | 88.0 | 2 | | 張三 | 71.0 | 3 | | 張三 | 60.0 | 4 | | 張三 | 66.0 | 5 | | 張三 | 91.0 | 6 | | 李四 | 77.0 | 1 | | 李四 | 73.0 | 2 | | 李四 | 84.0 | 3 | | 李四 | 93.0 | 4 | | 李四 | 64.0 | 5 | | 李四 | 91.0 | 6 | | 王二 | 97.0 | 1 | | 王二 | 89.0 | 2 | | 王二 | 81.0 | 3 | | 王二 | 79.0 | 4 | | 王二 | 93.0 | 5 | | 王二 | 88.0 | 6 | +---------+-------+-----+

總結

以上是生活随笔為你收集整理的MYsql建立学生成绩表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。