实验2 表数据插入、修改和删除
目的要求:
(1)学会在控制台中对数据库表进行插入、修改和删除数据操作
(2)了解各种数据类型的取值范围
(3)理解数据完整性约束的作用
(4)了解SQL语句对表数据操作的灵活控制功能
以下内容未修改数据库字符编码为utf-8,故为了方便采用拼音缩写。有需求的话可自行修改
接触外键约束:SET FOREIGN_KEY_CHECKS=0;
//Students表插入数据
insert into Students values('02','zzx','女','nmg','2001-05-01','h',null,'yy','wd');
insert into Students values('04','san','女','nmg','2001-06-22','mg',null,'sj','jsj');
insert into Students values('05','ljl','女','bj','2002-01-15','h',null,'sj','jsj');
insert into Students values('06','wyx','男','tj','2001-01-12','cx',null,'hs','sw');
insert into Students values('102','yxy','女','nmg','2000-03-09','h','党员','wgy','yy');
insert into Students values('104','ljb','男','ln','2000-12-13','cx','党员','wgy','yy');
insert into Students values('105','syy','女','nmg','2000-11-05','mg','党员','wgy','yy');
注:第一个数据为学号,第二个数据为姓名,第三个数据为性别,第四个数据为籍贯,第五个数据为生日,第五个数据为民族,第六个数据为政治面貌,第七个数据为院系,第八个数据为专业。
//Departments表插入数据
insert into Departments values('mg',null,'kxw','dhw','zj');
insert into Departments values('ls',null,'nxm','hk','wl');
insert into Departments values('wxy',null,'wrqqg','qxw','lq');
insert into Departments values('jg','jg','wlqqg','jme','lxw');
insert into Departments values('fs','fs','bfg','eyz','cwc');
insert into Departments values('jk',null,'blldgw','tl','zyx');
注:第一个数据为院系全称,第二个数据为院系简称,第三个数据为学院行政负责人,第四个数据为学院党政负责人,第五个数据为联系人。
//major表插入数据
insert into major values('01','sp','hs','工学');
insert into major values('02','sw','hs','哲学');
insert into major values('18','yd','ty','教育学');
insert into major values('19','rw','zj','经济学');
insert into major values('10','wd','yy','法学');
注:第一个数据为专业代码,第二个数据为专业名称,第三个数据为所属院系,第四个数据为专业类型。
//Course表插入数据
insert into Course values('dxyy','lq','wgy','gx','3');
insert into Course values('jsj','mxq','sj','gx','5');
insert into Course values('mks','zm','sj','gx','8');
insert into Course values('jds','wq','sj','gx','1');
insert into Course values('dxty','www','sj','gx','13');
insert into Course values('dxyy','lyn','yy','xx','12');
insert into Course values('gs','ml','sj','gx','11');
注:第一个数据为课程名称,第二个数据为授课教师,第三个数据为承担单位,第四个数据为课程属性,第五个数据为课程学分。
//Teacher表插入数据
insert into Teacher values('200110','ae','管理岗位','高级','sj',null,'2001.07');
insert into Teacher values('200733','TH','管理岗位','高级','sj',null,'2007.9');
insert into Teacher values('199223','kxw','管理岗位','高级','sj',null,null);
insert into Teacher values('199309','zyp','管理岗位','高级','sj',null,'1993.07');
insert into Teacher values('200117','wxy','管理岗位','高级','sj',null,'2001.07');
insert into Teacher values('201016','th','管理岗位','高级','sj',null,'2012.11');
insert into Teacher values('2006','wrd','管理岗位','高级','sj',null,'2006.28');
insert into Teacher values('2018','jzj','专业技术岗位','高级','ty',null,'2018.03');
insert into Teacher values('199303','dhw','专业技术岗位','高级','ty',null,'1999.03');
insert into Teacher values('200014','wp','专业技术岗位','高级','ty',null,'20000.7');
insert into Teacher values('200522','tl','专业技术岗位','副高级','zj',null,'2005.7');
insert into Teacher values('199626','zhg','专业技术岗位','副高级','zj',null,'1996.9');
insert into Teacher values('199521','hzq','专业技术岗位','副高级','yy',null,'1995.8');
insert into Teacher values('199902','wj','专业技术岗位','副高级','yy',null,'1999.3');
insert into Teacher values('200864','mhy','专业技术岗位','中级','wxy',null,'2008.08');
insert into Teacher values('200825','mhn','专业技术岗位','中级','wxy',null,'2008.08');
insert into Teacher values('200773','zy','专业技术岗位','中级','hs',null,'2007.1');
insert into Teacher values('200427','gzy','专业技术岗位','中级','hs',null,'2004.07');
insert into Teacher values('200630','wynt','专业技术岗位','中级','fs',null,'2006.7');
insert into Teacher values('200709','fhq','专业技术岗位','中级','fs',null,'2007.6');
insert into Teacher values('201319','bl','专业技术岗位','中级','jg',null,'2014.3');
insert into Teacher values('200902','lnn','专业技术岗位','中级','jg',null,'2029.9');
insert into Teacher values('201920','wy','专业技术岗位','中级','wgy',null,'2018.04');
insert into Teacher values('201921','wjj',null,null,null,null,null);
insert into Teacher values('202113','lyy','专业技术岗位','中级','mgy',null,'2021.07');
insert into Teacher values('202110','lhl','专业技术岗位','中级','mgy',null,'2021.08');
insert into Teacher values('201497','bpf','工勤技能岗位','中级','nxy',null,'2014.11');
insert into Teacher values('199007','hgj','工勤技能岗位','中级','nxy',null,null);
insert into Teacher values('200826','lwj','工勤技能岗位','初级','wz',null,'2008.08');
insert into Teacher values('200828','lq','工勤技能岗位','初级','wz',null,'2008.08');
insert into Teacher values('200830','mxq','工勤技能岗位','高级','wz',null,'2008.08');
insert into Teacher values('200702','yyj','工勤技能岗位','初级','wz',null,'2008.05');
注:第一个数据为教师工号,第二个数据为教师姓名,第三个数据为岗位类型,第四个数据为职称,第五个数据为所在院系,第六个数据为联系电话,第七个数据为参加工作年份。
//SC表插入数据
insert into SC values('102','yy','lq','90');
insert into SC values('112210102','byjc','lwr','80');
insert into SC values('112210102','sjys','jl','92');
insert into SC values('112210102','dxty','gxs','81');
insert into SC values('104','yy','lq','87');
insert into SC values('112210104','sx','hzq','86');
insert into SC values('112210104','dxty','djj','97');
insert into SC values('105','yy','lq','60');
insert into SC values('112210105','sx','hzq','45');
insert into SC values('112210105','dxty','djj','80');
insert into SC values('106','yy','wll','85');
insert into SC values('112210106','byjc','ljr','100');
insert into SC values('112210106','ty','gxs','96');
insert into SC values('112210106','sjys','jl','90');
insert into SC values('111','yy','wll','77');
insert into SC values('112210111','ty','hl','92');
insert into SC values('112210111','jl','xn','70');
insert into SC values('112210111','jsj','mxq','72');
insert into SC values('112210111','jds','wq','91');
insert into SC values('114','yy','wll','68');
insert into SC values('112210114','byjc','lwr','88');
insert into SC values('112210114','ty',null,'75');
注:第一个数据为学号,第二个数据为课程名称,第三个数据为授课教师,第四个数据为学生成绩。
向Students表中修改数据
向Students表中删除数据
向Departments表中修改数据
向Departments表中删除数据
向major表中修改数据
向major表中删除数据
向Course表中修改数据
向Course表中删除数据
向Teacher表中修改数据
向Teacher表中删除数据
向SC表中修改数据
向SC表中删除数据
使用SC显示表数据并检查