最新MySQL试题-测试、复习、查看.docx

上传人:啊飒飒 文档编号:10192387 上传时间:2021-04-27 格式:DOCX 页数:7 大小:30.53KB
返回 下载 相关 举报
最新MySQL试题-测试、复习、查看.docx_第1页
第1页 / 共7页
最新MySQL试题-测试、复习、查看.docx_第2页
第2页 / 共7页
最新MySQL试题-测试、复习、查看.docx_第3页
第3页 / 共7页
最新MySQL试题-测试、复习、查看.docx_第4页
第4页 / 共7页
最新MySQL试题-测试、复习、查看.docx_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《最新MySQL试题-测试、复习、查看.docx》由会员分享,可在线阅读,更多相关《最新MySQL试题-测试、复习、查看.docx(7页珍藏版)》请在三一文库上搜索。

1、学习-好资料设计三张表创建student表(学生表)Createtablestudent(Sidtinyintprimarykeyauto_increment,Snamechar(10),Sexchar(5),Sagetinyint,Sdeptchar(20);insertintostudent(Sid,Sname,Sex,Sage,Sdept)values(1,张三,女,20,IT);insertintostudent(Sid,Sname,Sex,Sage,Sdept)values(2,李四,女,25,info);insertintostudent(Sid,Sname,Sex,Sage,Sd

2、ept)values(3,王五,男,22,en);insertintostudent(Sid,Sname,Sex,Sage,Sdept)values(4,马云,女,28,ch);insertintostudent(Sid,Sname,Sex,Sage,Sdept)values(5,赵子龙,女,18,info);insertintostudent(Sid,Sname,Sex,Sage,Sdept)values(6,王小,女,21,info);insertintostudent(Sid,Sname,Sex,Sage,Sdept)values(7,赵龙龙,男,24,en);创建course表(课程表

3、)Createtablecourse(Cidtinyintprimarykeyauto_increment,Cnamechar(20),Ccredittinyint);insertintocoursevalues(1,数据结构,5);insertintocoursevalues(2,数据库,10);insertintocoursevalues(3,英语,3);insertintocoursevalues(4,数学,6);创建sc表(选课表)createtablesc(Sidtinyint,Cidint,Gradeint);insertintoscvalues(1,1,65);insertint

4、oscvalues(1,2,60);insertintoscvalues(1,4,90);insertintoscvalues(1,3,50);insertintoscvalues(2,2,100);insertintoscvalues(3,1,90);insertintoscvalues(6,2,70);insertintoscvalues(4,4,90);insertintoscvalues(5,1,95);insertintoscvalues(6,1,80);insertintoscvalues(7,3,80);创建admin表createtableadmin(idint(10),qqi

5、nt(20),uidint(5);创建province表createtableprovince(idint(10)primarykeyauto_increment,pnamevarchar(30);insertintoprovince(id,pname)values(2,上海);insertintoprovince(id,pname)values(3,广州);insertintoprovince(id,pname)values(4,成都);创建student2表createtablestudent2(idint(10)primarykeyauto_increment,namevarchar(3

6、0),pidint(10),foreignkey(pid)referencesprovince(id)ondeletecascade);正则查询建表创建表user两个字段一个id一个name更多精品文档学习-好资料Createtableuser(idint(10),namevarchar(20);Insertintouser(name)values(bat),(baet),(baaset),(atath),(astst);创建一个表,两个字段,商品名称,商品价格Createtablegoods(idint(10)primarykey,goodsNamevarchar(20),priceint(

7、20);InsertintogoodsValues(1,HuaWei,1000);InsertintogoodsValues(2,Vivo,1500);InsertintogoodsValues(3,iphone,3000);InsertintogoodsValues(4,honor,600);InsertintogoodsValues(5,HuaWei2,2000);Createtablestudent1(Idint(10)primarykeynotnullauto_increment,Usernamevarchar(30)unique,Passwordvarchar(30),Sexint(

8、10)default20);创建表indexd表Createtableindexd(idintprimarykeyauto_increment,namevarchar(20);创建存储过程d/createprocedurep10(numint)begindeclareiintdefault0;whileinumdoinsertintoindexd(name)values(concat(user,i);seti=i+1;endwhile;end/callp10(1000);创建一个user1表createtableuser1(idtinyint(4)primarykeyauto_incremen

9、t,namechar(10),priceint(10);1、查询student表全体学生学号和姓名selectSid,Snamefromstudent;2、查询sc表选修了课程的学生学号selectSidfromscgroupbySid;3、查询考试成绩不及格的学生selectdistinct(student.Sname)fromstudent,scwheresc.Grade60andsc.Sid=student.Sid;4、查询不在20-30岁年龄的学生select*fromstudentwhereSagenotbetween20and30;5、查询info、en系的学生姓名和年龄selec

10、tSname,Sage,SdeptfromstudentwhereSdeptin(info,en);6、查询所有姓王的学生信息Select*fromstudentwhereSnamelike王%;7、查询所有不姓王的学生信息Select*fromstudentwhereSnamenotlike王%;8、查询计算机系(info)年龄在20岁一下的学生姓名selectSnamefromstudentwhereSdept=infoandSage3;12、查询选修2号课程且成绩在90分以上的学生select*fromstudent,scwheresc.Cid=2andsc.Grade=90andsc.

11、Sid=student.Sid;13、查询选修了所有课程的同学select*fromstudentwherenotexists(select*fromcoursewherenotexists(select*fromscwheresc.Sid=student.Sidandsc.Cid=course.Cid);14、计算pi()/4的角度selectdegrees(pi()/4);15、绝对值函数:求-3的绝对值Selectabs(-3);17、求3.45向上取整SelectCeil(3.45);18、求90正弦的值SelectSin(90*(pi()/180);19、求e2自然常量SelectE

12、xp(2)20、求以10为底,100的对数的值;Selectlog10(100);21、截取小数点2.5935471358后5位数SelectTruncate(2.5935471358,5);22、随机生成一个三位数的随机数selectfloor(rand()*900+100);23、计算8的三次方Selectpow(8,3);24、截取字符串helloworld,输出world或者helloselectleft(helloworld,5);selectright(helloworld,5);selectsubstring(helloworld,1,5);/1:表示从哪个位置开始5:表示截取的

13、长度selectsubstring(helloworld,7,5);25、替换字符串mynameishan,把han替换成自己的名字Selectreplace(mynameishan,han,huqianwei);selectinsert(mynameishan,12,3,wangyuanyuan);26、填充字符串,在字符串hello后面添加自己的名字:如hellolucyselectrpad(hello,8,hu);27、在数据表admin结构中增加一个字段dep条件约束唯一varchar(30)类型Altertableadminadddepvarchar(30)unique;28、在数据

14、表admin结构中把dep字段改为sexAltertableadminchangedepsexvarchar(30);29、修改表名称更多精品文档学习-好资料将数据表名称admin修改为SadminAltertableadminrenameSadmin;altertableadminrenametoSadmin;30、修改数据类型将admin表qq数据类型int,修改为varchar(20);altertableadminmodifyqqvarchar(20);31、在admin表中添加一个salary字段类型为varchar(10)Altertableadminaddsalaryvarcha

15、r(10);32、在admin表中修改字段salary唯一性约束uniquealtertableadminmodifysalaryvarchar(10)unique;33、在admin表中在id字段后面添加一个depid字段int(10)altertableadminadddepidint(10)afterid;34、在admin表中删除uid字段altertableadmindropuid;35、连接字符串my,name,is,mysqlSelectconcat(my,name,is,mysql);36、使用分隔符-连接字符串my、name、is、mysqlSelectconcat_ws(-

16、,my,name,is,mysql);37、查询3是否在4、5、6中Select3in(4,5,6);38、在2、5、6、5中哪个数最小selectleast(2,5,6,5);39、查询3是否在5和9之间Select3between5and9;40、求字符串my的长度selectlength(my);41、左边字符串abcd截取3Selectleft(abcd,3);-abc42、字符串abcd反转SelectReverse(abcd);-dcba43、小写abcd转大写selectupper(abcd);值:ABCD44、字符串比较:比较aa与bb大小selectstrcmp(aa,bb)

17、;45、向字符串hello左边填充字符串abc,填充后的长度为9selectlpad(hello,9,abc);46、向字符串hello右边填充字符串abc,填充后的长度为9selectrpad(hello,9,abc);47、返回当前日期+时间selectnow();48、返回当前日期selectcurrent_date();49、返回系统时间Selectsysdate();更多精品文档学习-好资料50、返回当前时间的年Selectyear(now();值:当前的年51、返回2017-4-1第几周Selectweek(2017-4-1);值:1352、返回当前时间是星期几selectdayo

18、fweek(now();/1表示星期天,2表示星期一53、返回2017-4-6年当中的第几天Selectdayofyear(2017-4-6);值:96;54、返回2017-4-6和2017-4-1两个日期相隔天数Selectdatediff(2017-4-6,2017-4-1);55、查看学生表的所有信息Select*fromstudent;56、查询user表中b开头的字段数据Select*fromuserwherenameregexpb;.57、查询user表中b与t之间有单个字符的数据Select*fromuserwherenameregexpb.t;/58、查询user表中有a或者b

19、字符的数据Select*fromuserwherenameregexpa,b;59、查询选修课学生及格的同学Select*fromscgroupbySidhavingGrade=60;60、查询所有学生选修的几门课SelectSid,count(*)fromscgroupbySid;61、查询所有学生选修课的平均成绩SelectSid,avg(Grade)fromscgroupbySid;62、平均成绩大于60的学号和平均成绩的学生SelectSid,avg(Grade)fromscgroupbySidhavingavg(Grade)=60;63、新建一个以自己名字为名称的数据库Created

20、atabasehuqianwei;64、创建学号(id)、姓名(Name)的student1表Createtablestudent1(Idint,Namevarchar(30);65、创建存储过程p1,查询student表的所有信息d/Createprocedurep1()beginselect*fromstudent;end/Callp1()/66、删除存储过程p5Dropprocedurep5/不能加括号67、查询学号最大的学生姓名及年龄SelectSname,SagefromstudentorderbySiddesclimit1;68、查看student表结构descstudent;更多

21、精品文档学习-好资料69、逻辑运算:逻辑1与0Select1&0;Select1and0;70、逻辑运算:逻辑1或0Select1|0;Select1or0;71、逻辑运算:逻辑非0Select!0;72、存储过程p3求c=a+b加法运算求3=1+2createprocedurep3(aint,bint)begindeclarecintdefault0;setc=a+b;selectcassum;end/callp3(1,2)/73、在indexd索引表里添加索引indexNameAltertableindexdaddindexindexName(name);74、在indexd索引表里删除索

22、引indexNameAltertableindexddropindexindexName;DropindexindexNameonindexd;75、查询goods表中price价格在500到2000的商品Select*fromgoodswhereprice=500andprice2000;76、查询goods表中商品名称goodsName以H开头Select*fromgoodswheregoodsNamelikeH%;77、查询goods表中当前价格price是否在(3000,500,800,400,200)select*fromgoodswherepricein(3000,500,800,

23、400,200);78、求余:5/2的余SelectMod(5,2);79、返回2017-4-1时间的季度Selectquarter(2017-4-1);值:280、时间10:20:30转化为秒Selecttime_to_sec(10:20:30);值:3723081、在indexd表中100id100andid200;82、删除indexd表的视图vindexddropviewvindexd;83、创建触发器t1,在indexd表中的每行插入indexd2Createtriggert1beforeinsertonindexdforeachrowBegin更多精品文档学习-好资料Inserti

24、ntoindexd2(name)values(new.name);End/84、向province表pname字段插入数据:重庆insertintoprovince(pname)values(重庆);85、向student2表插入学生信息数据name=自己的名字、pid=2(注意student2有外键)insertintostudent2(name,pid)values(自己的名字,2);86、删除province表id为2的数据deletefromprovincewhereid=2;87、删除student2中的外键altertablestudent2dropforeignkeystudent2_ibfk_1;88、89、修改admin表引擎为myisamaltertableadminengine=myisam;89、显示数据库引擎showengines;90、向user1表中name,price插入入多条数据insertintouser1(name,price)values(rr,30),(uu,60),(ii,70);更多精品文档

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1