MYSQL表结构和样本数据相关实验

编程入门 行业动态 更新时间:2024-10-15 02:32:25

MYSQL表结构和<a href=https://www.elefans.com/category/jswz/34/1766853.html style=样本数据相关实验"/>

MYSQL表结构和样本数据相关实验

                              学生信息数据库(stusys)的表结构和样本数据

一.学生信息数据库(stusys)中的表------学生表(student),课程表(course),成绩表(score),教师表(teacher),讲课表(lecture).如下

二.操作

1.创建数据库中的sutsys,代码及运行结果如下:

create database stusys;

2.进入数据库stusys中

use stusys;

 

 3.#创建学生表,课程表,成绩表,教师表,讲课表

(1)学生表
create table student
(
    sno char(6) not null primary key comment '学号',
    sname char(8) not null comment '姓名',
    ssex char(20) not null default '男' comment '性别',
    sbirthdat date not null comment '出生日期',
    speciality char(12) null comment '专业',
    tc tinyint null comment  '总学分'
);


(2)课程表
create table course
(
    cno char(4) not null primary key comment '课程号',
    cname char(16) not null comment '课程名',
    credit tinyint null comment '学分'
);


(3)成绩表
create table score
(
    sno char(6) not null comment '学号',
    cno char(4) not null comment '课程号',
    grade tinyint null comment '成绩',
    primary key(sno,cno)
);


(4)教师表
create table teacher
(
    tno char(6) not null primary key comment '教师编号',
    tname char(8) not null default '男' comment '姓名',
    tsex char(2) not null comment '性别',
    tbirthday date not null comment '出生日期',
    title char(12) null comment '职称',
    school char(12) null comment '学院'
);


(5)讲课表
create table lecture
(
    tno char(6) not null comment '教师编号',
    cno char(4) not null comment '课程号',
    location char(10) null comment '上课地点',
    primary key(tno,cno)
);

 4.添加数据表内容/记录 

注:这里已经在stusys中,不需要再次进入,如果数据结构库表较多,需 use 库名 进入特定库

 (1)学生表

insert into student
    values
        ('191001','刘清泉','男','1998-06-21','计算机',52),
        ('191002','张慧玲','女','1999-11-07','计算机',50),
        ('191003','冯涛','男','1999-08-12','计算机',52),
        ('196001','董明霞','女','1999-05-02','通信',50),
        ('196002','李茜','女','1998-07-25','通信',48),
        ('196004','周俊文','男','1998-03-10','通信',52);

 

 (2)课程表

insert into course
    values
        ('1004','数据库系统',4),
        ('1017','操作系统',3),
        ('4002','数字电路',3),
        ('8001','高等数学',4),
        ('1201','英语',4);

 

 (3)成绩表

insert into score
    values
        ('191001','1004',95),
        ('191002','1004',87),
        ('191003','1004',93),
        ('196001','4002',90),
        ('196002','4002',79),
        ('196004','4002',88),
        ('191001','8001',92),
        ('191002','8001',88),
        ('191003','8001',84),
        ('196001','8001',87),
        ('196002','8001',null),
        ('196004','8001',94),
        ('191001','1201',92),
        ('191002','1201',78),
        ('191003','1201',93),
        ('196001','1201',84),
        ('196002','1201',76),
        ('196004','1201',92);

 

 (4)教师表

insert into teacher
    values
        ('100006','何艺杰','男','1970-06-23','教授','计算机学院'),
        ('100023','孙浩然','男','1979-04-09','教授','计算机学院'),
        ('400017','李亚兰','女','1988-11-04','讲师','通信学院'),
        ('180028','袁万明','男','1978-08-15','副教授','数学学院'),
        ('120046','刘颖','女','1976-12-15','副教授','外国语学院');

 

 (5)讲课表

insert into lecture
    values
        ('100006','1004','2-311'),
        ('400017','4002','1-106'),
        ('800028','8001','6-104'),
        ('120046','1201','6-215');

5.最后检验数据是否插入成功

 select *from student;


select *from course;


select *from score;


select *from teacher;


select *from lecture;

 

 

 如图,即为插入数据后表

 

 

 

更多推荐

MYSQL表结构和样本数据相关实验

本文发布于:2024-03-10 17:14:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1728558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样本   结构   数据   MYSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!