关于oracle的sql命令操作

表修改

创建表(含主键/外键约束)

create table CourseInfo(couserID varchar2(8) primary key,courseName varchar2(32) not null,departmentCode varchar2(5) not null,credit numeric(3,1) not null,resume varchar2(255) null,foreign key(departmentCode) references DepartmentInfo(departmentCode));

增加属性列

alter table classInfo add(temp varchar2(20));

修改属性名

alter table ClassInfo rename column teacherID to FK_Teacher;

增加外键约束

alter table ClassInfo add foreign key(FK_Teacher) references TeacherInfo(teacherID);

设置空值

alter table StudentInfo modify studentName null;

删除约束

alter table ClassInfo drop constraint courseID;

基本查询

范围查询

select * from CourseInfo where credit>=1 and credit<=3;
select * from CourseInfo where credit between 1 and 3;

降序排列

select * from ClassInfo order by classID desc;

表复制

Create table CourseInfoTemp as select * from CourseInfo;

查询时修改部分属性值

select teacherID,teacherName,case sex when ‘f’ then ‘female’ when ‘m’ then ‘man’ else ‘unknown’ end from TeacherInfo;

分组查询

select studentID,studentName,departmentCode from StudentInfo where studentID in (select studentID from SelectiveInfo group by studentID having count(studentID)>2);

查询平均值

select classID,avg(grade) from SelectiveInfo1 group by classID;

左右连接

Select TeacherInfo.teacherID,TeacherInfo.teacherID,ClassInfo1.classID from TeacherInfo,ClassInfo1 where TeacherInfo.teacherID=ClassInfo1.teacherID(+);

创建视图

Create view showSelective as select StudentInfo.studentID,StudentInfo.studentName,departmentInfo.departmentName,ClassInfo.className,CourseInfo.courseName,CourseName.credit,TeacherInfo.teacherName where StudentInfo.departmentCode=departmentInfo.departmentCode and StudentInfo.studentID=SelectiveInfo.studentID and SelectiveInfo.classID=ClassInfo.classID and ClassInfo.courseID=CourseInfo.courseID and ClassInfo.teacherID=TeacherInfo.teacherID;

模糊查询

select * from StudentInfo where studentName like ‘%he%’;

索引操作

创建B树索引

create index idx1 on StudentInfo(studentName);

创建位图索引

create bitmap index idx2 on StudentInfo(DepartmentCode);

查询索引的使用情况

alter index idx1 monitoring usage;//开启索引监控
select * from v$object_usage;//查看索引使用情况

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值