本次mysql期末上機(jī)考試題主要涵蓋了以下幾個(gè)方面:
1.基本sql語(yǔ)句的使用
--創(chuàng)建表 create table student( id int primary key auto_increment, name varchar(20) not null, gender char(1) not null, age int, email varchar(50) ); --插入數(shù)據(jù) insert into student(name,gender,age,email) values('張三','男',20,'zhangsan@qq.com'); insert into student(name,gender,age,email) values('李四','女',19,'lisi@qq.com'); insert into student(name,gender,age,email) values('王五','男',22,'wangwu@qq.com'); insert into student(name,gender,age,email) values('趙六','女',21,'zhaoliu@qq.com'); --查詢數(shù)據(jù) select * from student; --刪除數(shù)據(jù) delete from student where id=3; --更新數(shù)據(jù) update student set email='zhaosi@qq.com' where id=4;
2.外鍵的使用
--創(chuàng)建兩張表,student和score create table student( id int primary key auto_increment, name varchar(20) not null, gender char(1) not null, age int, email varchar(50) ); create table score( id int primary key auto_increment, course varchar(20) not null, score int not null, student_id int not null, foreign key(student_id) references student(id) ); --插入數(shù)據(jù) insert into student(name,gender,age,email) values('張三','男',20,'zhangsan@qq.com'); insert into student(name,gender,age,email) values('李四','女',19,'lisi@qq.com'); insert into student(name,gender,age,email) values('王五','男',22,'wangwu@qq.com'); insert into student(name,gender,age,email) values('趙六','女',21,'zhaoliu@qq.com'); insert into score(course,score,student_id) values('數(shù)學(xué)',80,1); insert into score(course,score,student_id) values('語(yǔ)文',90,1); insert into score(course,score,student_id) values('英語(yǔ)',85,2); --查詢數(shù)據(jù) select student.name,score.course,score.score from student,score where student.id=score.student_id;
3.事務(wù)的使用
--開(kāi)啟事務(wù),將兩個(gè)操作放在一個(gè)事務(wù)中 begin; insert into student(name,gender,age,email) values('小明','男',18,'xiaoming@qq.com'); insert into score(course,score,student_id) values('物理',95,5); commit;
本次期末上機(jī)考試內(nèi)容全面,覆蓋了mysql數(shù)據(jù)庫(kù)的各個(gè)方面,需要同學(xué)們認(rèn)真復(fù)習(xí),熟練掌握。通過(guò)本次考試,同學(xué)們能夠更加深入地了解mysql的使用方法和技巧,為自己以后的學(xué)習(xí)和工作打下堅(jiān)實(shí)的基礎(chǔ)。