附件源代码可在资源下载demo3.sql
use stuexpm;
#1.向TeacherInfo表插入样本数据
insert into teacherinfo
values('100005','李慧强','男','19680925','计算机学院','北京市海淀区'),
('400021','陈霞飞','女','19751207','通信学院','上海市黄浦区'),
('800004','刘泉明','男','19780816','数学学院','广州市越秀区'),
('100024','刘松','男','19760217','计算机学院','北京市海淀区'),
('120007','张莉','女','19820321','外国语学院','成都市锦江区');
#2.向courseinfo表插入样本数据
insert into courseinfo
values('1004','数据库系统',4),
('1025','物联网技术',3),
('4002','数字电路',3),
('8001','高等数学',4),
('1201','英语',4);
create table teacherinfo1 like teacherinfo;
#3.使用insert into···select···语句,将teacherinfo表的记录快速插入teacherinfo1表中
insert into teacherinfo1
select * from teacherinfo;
create table teacherinfo2 like teacherinfo;
#4.1省略列名表,插入记录('100005','李慧强','男','19680925','计算机学院','北京市海淀区');
insert into teacherinfo2
value('100005','李慧强','男','19680925','计算机学院','北京市海淀区');
#4.2不省略列名表,插入教师编号为400021,姓名为“陈霞飞”,地址为“上海市黄浦区”,学院为“通信学院”,出生日期为19751207,性别为“女”的记录
insert into teacherinfo2 (TeacherID,TeacherName,Address,School,TeacherBirthday,TeacherSex)
value('400021','陈霞飞','上海市黄浦区','通信学院','19751207','女');
#4.3插入教师编号为800004,姓名为“刘泉明”,性别为“男”,取默认值,出生日期为19780816,学院和地址为空的记录
insert into teacherinfo2(TeacherID,TeacherName,TeacherBirthday)
value('800004','刘泉明','19780816');
#5.在teacherinfo1表中,更新教师编号为120007的记录,将出生日期改为“1983-09-19”
update teacherinfo1
set TeacherBirthday='1983-09-19'
where TeacherID='120007';
#6.在teacherinfo1表中,将性别为“男”的记录的家庭住址都改为“上海市浦东新区”
update teacherinfo1
set address ='上海市浦东新区'
where TeacherSex='男';
#7.在teacherinfo1表中,删除教师编号为400021的记录
delete from teacherinfo1
where TeacherID='400021';
#8.1使用delete语句,删除teacherinfo1表中的全部记录
delete from teacherinfo1;
#8.2使用truncate语句,删除teacherinfo2表中的全部记录
truncate teacherinfo2;