本次mysql期末上機考試題主要涵蓋了以下幾個方面:
1.基本sql語句的使用
--創建表 create table student( id int primary key auto_increment, name varchar(20) not null, gender char(1) not null, age int, email varchar(50) ); --插入數據 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'); --查詢數據 select * from student; --刪除數據 delete from student where id=3; --更新數據 update student set email='zhaosi@qq.com' where id=4;
2.外鍵的使用
--創建兩張表,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) ); --插入數據 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('數學',80,1); insert into score(course,score,student_id) values('語文',90,1); insert into score(course,score,student_id) values('英語',85,2); --查詢數據 select student.name,score.course,score.score from student,score where student.id=score.student_id;
3.事務的使用
--開啟事務,將兩個操作放在一個事務中 begin; insert into student(name,gender,age,email) values('小明','男',18,'xiaoming@qq.com'); insert into score(course,score,student_id) values('物理',95,5); commit;
本次期末上機考試內容全面,覆蓋了mysql數據庫的各個方面,需要同學們認真復習,熟練掌握。通過本次考試,同學們能夠更加深入地了解mysql的使用方法和技巧,為自己以后的學習和工作打下堅實的基礎。