目录
插入
向学生表中插入数据
INSERT INTO student(sid,sname,birt,sex,phone,address)
VALUES
(1,'赵雷','1990-01-01','男','13112312312','黑龙江省黑河市'),
(2,'钱电','1990-12-21','男','13154649876','山东省青岛市'),
(3,'孙风','1990-05-20','男','15846541543','黑龙江省哈尔滨市'),
(4,'李云','1990-08-06','男','18623021203','山东省青岛市'),
(5,'周梅','1991-12-01','女','13121648970','山东省青岛市'),
(6,'吴兰','1992-03-01','女','15831564231','山东省青岛市'),
(7,'郑竹','1989-07-01','女','18645103000','山东省青岛市'),
(8,'王菊','1990-01-20','女','13112332100','山东省青岛市');
向教师表中插入数据
INSERT INTO teacher (sid,tname,sex,porfession)
VALUES
(1,'张三','男','教授'),
(2,'李四','男','副教授'),
(3,'王五','女','讲师'),
(4,'赵六','男','助教');
向成绩单中插入数据
INSERT INTO sc(sid,cid,score)
VALUES
(1,1,'90'),
(1,2,'80'),
(1,3,'90'),
(2,1,'70'),
(2,2,'60'),
(2,3,'80'),
(3,1,'80'),
(3,2,'80'),
(3,3,'80'),
(4,1,'50'),
(4,2,'30'),
(4,3,'20'),
(5,1,'76'),
(5,2,'87'),
(6,1,'31'),
(6,3,'34'),
(6,2,'6'),
(7,2,'89'),
(7,3,'98');
向课程表中插入数据
INSERT INTO course (cid,cname,tid,cerdit)
VALUES
(1,'JAVA基础',2,3),
(2,'高等数学',1,4),
(3,'MySQL',3,4),
(4,'软件测试',1,1);
修改
#将姓名为孙风的学生的地址改为“黑龙江省牡丹江市”
UPDATE student SET address='黑龙江省牡丹江市' where sname='孙风';
#将出生日期在1990-01-01到1990-04-30的学生的性别改为男
UPDATE student SET sex ='男' WHERE birth BETWEEN '1990-01-01'AND'1990-04-30';
#将出生日期在1990-01-01到1990-04-30的学生的性别改为女
UPDATE student SET sex ='女' WHERE birth BETWEEN '1990-01-01'AND'1990-04-30';
#将姓名为张三的老师名字改为张三一
UPDATE teacher SET tname = '张三一' WHERE tname='张三';
#将张姓的老师职称改为助教
UPDATE teacher SET profession ="助教" WHERE tname LIKE"张%"
#将JAVA课程的学分在原来基础上加+1
UPDATE course SET credit=credit+1 WHERE cname ="JAVA基础";
#将高等数学课程的学分减为原来的一半,假设不知道原来学分是多少
UPDATE course set credit=credit/2 WHERE cname = '高等数学';
UPDATE course set credit=0.5*credit WHERE cname = '高等数学';
#将成绩小于10的学生的成绩加10分
UPDATE sc SET score =score+10 WHERE score<10;