数据库-数据更新

1.插入数据

1.1 插入单行数据

在course中插入一行数据,四项数据为(‘X004‘,‘计算机前沿‘,2,‘选修‘)
insert into Course(Cno,Cname,Ccredit,XKLB)
values(‘X004‘,‘计算机前沿‘,2,‘选修‘)

1.2 插入子查询结果

将学生表中的学号,姓名,性别抽取出来,插入到Teacher表中,所有新插入的数据,职称为讲师
insert into Teacher(Tno,Tname,Tsex)
select Sno,Sname,Ssex,‘讲师‘ from Studnet

1.3 查询创建新表

将teacher中职称为教授的信息,存入到一张目前还不存在的experts表
select * into experts from teacher
where Tprot=‘教授‘

2.更新数据

2.1 修改特定行

将course表中编号是B002的课程,学分修改为3分
update course set ccredit=3
where cno=‘B002‘

2.2 带子查询的修改

对学生表,将现有的专业字段,用来存放学生选修的第一门课程的编号
update student
set smajor
(select top 1 cno from sc where sc.sno=student.sno)

3.删除数据

3.1 删除满足条件的行

删除course表中编号为B009的记录
delete from course
where cno=‘B009‘

3.2 带子查询的删除

对course表中,没有任何学生选修过的课程,执行删除操作
delete from course where cno not in
(select cno from sc)

数据库-数据更新

上一篇:如何通过adb命令录制视频


下一篇:Linux下安装MongoDB 4.2数据库--使用网络yum方式