目录
创建一个数据库
表设计
表结构展示
插入数据
创建一个数据库
create database db_scg;
讯享网
表设计
学生表t_student:学号sno(主键) 、姓名sname 、性别sgender
讯享网create table t_student( sno int(8) primary key not null, sname varchar(8) not null, sgender char(1) not null );课程表t_course:课程id(主键)cid、课程名称cname
create table t_course( cid int(3) primary key not null, cname varchar(10) not null );成绩表t_grade: 成绩id(主键)gid、 学生学号 sno、课程id cid、分数 score
讯享网create table t_grade( gid int primary key not null, sno int(8) not null, cid int(3) not null, score int(3) );
给成绩表t_grade创建外键:
与t_student表
alter table t_grade add constraint fk_sno foreign key(sno) references t_student(sno);与t_course表
讯享网alter table t_grade add constraint fk_cid foreign key(cid) references t_course(cid);
表结构展示
插入数据
往t_student表插入数据:
insert into t_student(sno,sname,sgender) values(,'张三','男'),(,'李四','女'),(,'王五','男');
往t_course表插入数据:
讯享网insert into t_course(cid,cname) values(1,'数学'),(2,'语文'),(3,'英语');
往t_grade表插入数据
insert into t_grade(gid,sno,cid,score) values(1,,2,80),(2,,2,85),(3,,3,95),(4,,3,94),(5,,1,96);







版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/91754.html