#(1)创建数据库stuexpm
create database stuexpm;
#(2)创建studentinfo表,显示studentinfo表的基本结构
#表4.9
use stuexpm;
create table StudentInfo
(
StudentID varchar(6) not null primary key comment'学号',
Name varchar(8) not null comment'姓名',
Sex varchar(2) not null default '男' comment'性别',
Birthdar date not null comment'出生日期',
Speciality varchar(12) null comment'专业',
Address varchar(50) null comment'家庭地址'
)comment '学生表';
#(3)由studentinfo表使用复制方式创建studentinfo1表
create table StudentInfo1 like StudentInfo;
#(4)在studentinfo表中增加一列stuno,添加到表的第1列,不为空,取值唯一并自动增加,显示studentinfo表的基本结构
alter table StudentInfo add column StuNo int not null unique auto_increment first;
#(5)将studentinfo1表的address 列修改 为city ,将数据类型改为char,可为空,默认值为"北京",显示studentinfo1表的基本结构
alter table StudentInfo1 change column Address City char(10) default '北京';
desc StudentInfo1;
#(6)将studentinfo1表的speciality 列修改为school,将数据类型改为char,可为空,默认值为"计算机学院"
alter table StudentInfo1 change column Speciality School char(12) default '计算机学院';
desc StudentInfo1;
#(7)将studentinfo1表的city列的默认值修改为"上海"
alter table StudentInfo1 alter column City drop default;
alter table StudentInfo1 alter column City set default'上海';
desc StudentInfo1;
#(8)将studentinfo1表的city列的类型修改为varchar(20),并移到列Name之后
alter table StudentInfo1 modify column City varchar(20) after Name;
desc StudentInfo1;
#(9)在studentinfo1表中删除stuno列
alter table studentinfoStudentInfo drop StuNo;
desc StudentInfo;
#(10)将studentinfo1表更名为studentinfo2表
alter table StudentInfo1 rename to StudentInfo2;
show tables;
#(11)删除studentinfo2表
#添加数据内容/记录
#P81-例5.4
use stuexpm;
insert into StudentInfo
values
('181001','成志强','男','1988-08-17','计算机','北京市海淀区'),
('181002','孙红梅','女','1997-11-23','计算机','成都市锦江区'),
('181003','朱丽','女','1998-02-19','计算机','北京市海淀区'),
('184001','王志勇','男','1997-12-05','电子信息工程','null'),
('184002','周潞潞','女','1998-02-24','电子信息工程','上海市浦东区'),
('184004','郑永波','男','1997-09-19','电子信息工程','上海市浦东区');
#查看数据表内容记录
select * from studentinfo;
create table courseinfo
(
courseid varchar(4) not null primary key comment '课程号',
coursename varchar(16) not null comment '课程名',
credit tinyint null comment '学分'
)comment '学生表';
create table scoreinfo
(
studentid varchar(6) not null comment'学号',
courseid varchar(4) not null comment'课程号',
grade tinyint null comment'成绩',
primary key(studentid,courseid)
);
create table teacherinfo
(
teacherid varchar(6) not null primary key comment'教师编号',
teachername varchar(8) not null comment'姓名',
teachersex varchar(2) not null default '男' comment'性别',
teacherbirthday date not null comment'出生日期',
school varchar(12) null comment'学院',
address varchar(20) null comment'地址'
);
insert into courseinfo
values
('1004','数据库系统','4'),
('1025','物联网技术','3'),
('4002','数字电路','3'),
('801','高等数学','4'),
('1201','英语','4');
select * from courseinfo;
insert into scoreinfo
values
('181001','1004','95'),
('181002','1004','85'),
('181003','1004','91'),
('184001','4002','93'),
('184002','4002','76'),
('184004','4002','88'),
('181001','8001','94'),
('181002','8001','89'),
('181003','8001','86'),
('184001','8001','85'),
('184002','8001',null),
('184004','8001','94'),
('181001','1201','92'),
('181002','1201','78'),
('181003','1201','94'),
('184001','1201','85'),
('184002','1201','79'),
('184004','1201','94');
select * from scoreinfo;
insert into teacherinfo
values
('100005','李慧强','男','1968-09-25','计算机学院','北京市海淀区'),
('100024','刘松','男','1976-02-17','计算机学院','北京市海淀区'),
('400021','陈霞飞','女','1975-12-07','通信学院','上海市黄浦区'),
('800004','柳泉明','男','1978-08-16','数学学院','广州市越秀区'),
('120007','张莉','女','1980-03-21','外国语学院','成都市锦江区');文章来源:https://www.toymoban.com/news/detail-754121.html
select * from teacherinfo;文章来源地址https://www.toymoban.com/news/detail-754121.html
到了这里,关于学生信息数据库(stusys)的表结构和样本数据的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!