0
点赞
收藏
分享

微信扫一扫

Oracle增删改

--相表中插入一条数据
INSERT INTO "Grade"("GradeID","GradeIdName")
values(1,'20级中职');


--如果按序插入,可以省略字段列表
INSERT INTO "Grade"
values(2,'19级中职');


--插入多条数据记录
insert all
into "Grade" values(3,'18级中职')
into "Grade" values(4,'17级中职')
into "Grade" values(5,'16级中职')
select 1 from dual;


--插入默认值
insert into "Grade"
values(6,default);


--创建电话号码表PhoneList
create table "PhoneList"(
"StudentNo" number(11) not null,
"StudentName" VARCHAR2 (20) not null,
"Sex" char(2) not null,
"Phone" VARCHAR2(20) not null
);


---从原表Student中抽取字段插入到PhoneList中
insert into "PhoneList"("StudentNo","StudentName","Sex","Phone")
select "StudentNo","StudentName","Sex","Phone"
from "Student";


--更新记录,将学生表的第二个学生密码修改为8888
update "Student"
set "LoginPwd"='8888'
where "StudentNo"=2;


--更新记录,将95分及以下的学生成绩全部+5
update "Result"
set "StudentResult"="StudentResult"+5,"SubjectNo"=4
where "StudentResult"<=95;


--更新记录,将QQ邮箱为空的学生表的邮箱改为aaaqq.com
update "Student"
set "Email"='aaaqq.com'
where "Email" is null; --is null:为空 is not null:不为空


--删除记录
delete from "Student"
where "StudentNo"=3;


--清空表数据,保留表结构,删除的数据不可恢复,慎用!
truncate table "Student";

举报

相关推荐

0 条评论