【Oracle】实验10:索引管理

考核内容
     1、连接信息检测,要求如下:
         1)保证第2次实验中服务器端配置的第1个监听端口可以正常工作,
         2)保证使用第2次实验中客户端配置的第5个服务命名可以成功创建会话。
     2、创建存放索引的表空间(OMF机制)并维护数据,要求如下:
         1)①第1个索引表空间信息:
         2)①--- 基本信息:
         3)①------- 表空间名命名为TAI_544,
         4)①------- 块大小为8KB;
         5)①--- 文件信息:
         6)①------- 与第3个普通表空间包含的文件放在一起,
         7)①------- 文件大小(块数)为1024,
         8)①------- 文件自动扩展特性为“不支持”;
         9)②第2个索引表空间信息:
        10)②--- 基本信息:
        11)②------- 表空间名命名为TDI_843,
        12)②------- 块大小8KB;
        13)②--- 文件信息:
        14)②------- 与第5个普通表空间包含的文件放在一起,
        15)②------- 文件大小(块数)为9216,
        16)②------- 文件自动扩展特性为“不支持”;
        17)③第3个索引表空间信息:
        18)③--- 基本信息:
        19)③------- 表空间名命名为THI_644,
        20)③------- 块大小8KB;
        21)③--- 文件信息:
        22)③------- 与第2个普通表空间包含的文件放在一起,
        23)③------- 文件大小(块数)为7168,
        24)③------- 文件自动扩展特性为“不支持”,
        25)④确认上次创建的非全局临时表的所有记录中每列都不为空(大对象列除外)。。
     3、在非分区表上创建普通索引,要求如下:
         1)⑤以system用户登录,创建以下索引:
         2)⑤--- 索引名命名规范:索引字段名_表名_ind,
         3)⑤--- 建索引的表说明为“索引组织的表”,
         4)⑤--- 建索引的字段说明为“员工工种”,
         5)⑤--- 存储表空间为第3个索引表空间。
     4、在分区表上创建分区索引,要求如下:
         1)⑥以system用户登录,创建以下索引,
         2)⑥--- 索引名命名规范:索引字段名_表名_ind,
         3)⑥--- 建索引的表说明为“分区表”,
         4)⑥--- 建索引的字段说明为“月生产量”,
         5)⑥--- 以下是分区的描述信息,
         6)⑥------- 分区类别为全局分区,
         7)⑥------- 分区类型为范围分区,
         8)⑥------- 分区字段为“月生产量”,
         9)⑥------- 分区数为3,
        10)⑥------- 分区名命名规范:分区字段名_表名_分区号_par,
        11)⑥------- 以下是分区的描述信息,
        12)⑥-------   第1个分区描述如下,
        13)⑥-------     (a)上限值自行定义,不做检查,
        14)⑥-------     (a)存储表空间为第2个索引表空间,
        15)⑥-------   第2个分区描述如下,
        16)⑥-------     (b)上限值自行定义,不做检查,
        17)⑥-------     (b)存储表空间为第1个索引表空间,
        18)⑥-------   第3个分区描述如下:
        19)⑥-------     (c)上限值自行定义,不做检查,
        20)⑥-------     (c)存储表空间为第3个索引表空间。
     5、监控索引并维护数据,要求如下:
         1)⑦索引监控:
         2)⑦--- 索引为分区索引,
         3)⑦--- 监控状态为关闭,
         4)⑦--- 使用状态为使用,
         5)⑦--- 监控数量为1,
         6)⑧确认之前创建的分区表中第1、2、4列都不重复,
         7)⑧确认之前创建的索引组织的表、包含大对象段的表、第1个簇表中第1、2、4、5列都不重复,
         8)⑧确认之前创建第2个簇表中第1、2列都不重复。

代码:

//打开第九次实验要求
与第1个-还原表空间:D:\ORACLE\AT647001C\
与第4个-第6个-与第5个-临时表空间:F:\ORACLE\AT647001I\
与第2个-辅助表空间:D:\ORACLE\AT647001C\
与第3个-系统表空间:E:\ORACLE\AT647001E\
//标准块大小为2KB,所以要alter system set db_8k_cache_size=1;
alter system set db_create_file_dest='E:\ORACLE\AT647001E\';
alter system set db_8k_cache_size=1;
create tablespace TAI_544 blocksize 8k datafile size 8192k autoextend off;

alter system set db_create_file_dest='F:\ORACLE\AT647001I\';
alter system set db_8k_cache_size=1;
create tablespace TDI_843 blocksize 8k datafile size 73728k autoextend off;

alter system set db_create_file_dest='D:\ORACLE\AT647001C\';
alter system set db_8k_cache_size=1;
create tablespace THI_644 blocksize 8k datafile size 57344k autoextend off;

conn system/647001
Alter table RJEMP882 move mapping table;//如果是索引组织表,那就要删除映像表
CREATE BITMAP INDEX e_type_RJEMP882_ind ON RJEMP882(e_type) TABLESPACE THI_644;

全局索引(global):
Create index pnum_RJPAR671_ind on RJPAR671(pnum)
Global partition by range(pnum)
(
partition pnum_RJPAR671_1_par values less than (100) tablespace TDI_843,
Partition pnum_RJPAR671_2_par values less than(200) tablespace TAI_544,
Partition pnum_RJPAR671_3_par values less than (maxvalue) tablespace THI_644
);
本地索引(local):
Create bitmap index stuleader_RJSTU081_i on RJSTU081(stuleader) local
(
  partition stuno_RJSTU081_1_p  tablespace TGI_110,
  Partition stuno_RJSTU081_2_p  tablespace TDI_846,
  Partition stuno_RJSTU081_3_p  tablespace TJI_744
);

alter index pnum_RJPAR671_ind monitoring usage;
select * from RJPAR671 where pnum=10;//随便查询建索引字段的值-》使用状态为使用
select * from v$object_usage;
alter index pnum_RJPAR671_ind nomonitoring usage;
//开始监控:alter index index_name monitoring usage;
//检查使用状态:select * from v$object_usage;
//停止监控:alter index index_name nomonitoring usage;

模板:

//打开第九次实验要求
与第1个-还原表空间:D:\ORACLE\AT647001C\
与第4个-第6个-与第5个-临时表空间:F:\ORACLE\AT647001I\
与第2个-辅助表空间:D:\ORACLE\AT647001C\
与第3个-系统表空间:E:\ORACLE\AT647001E\
//标准块大小为2KB,所以要alter system set db_8k_cache_size=1;

2、创建存放索引的表空间(OMF机制):

alter system set db_create_file_dest='第几个表空间';
alter system set db_8k_cache_size=1;
create tablespace 表空间名 blocksize 8k datafile size m autoextend off;
//如果是文件大小(块数),那就!!!本题的k*块数!!!

3、在非分区表上创建普通索引:

conn system/647001
Alter table 建索引表表名 move mapping table;
//在索引组织表建立索引时需先添加映像表(只有索引组织表需要)
//Alter table 建索引表表名 move nomapping;//建错了删除
CREATE BITMAP INDEX 索引名 ON 表名(字段名) TABLESPACE 第几个索引表空间;
//有重复建BITMAP索引

4、在分区表上创建分区索引:
全局索引(global):

Create index 索引名 on 建索引的表(建索引的字段)
Global partition by range(分区字段)
(
  partition 分区命名 values less than (上限值) tablespace 第几个索引表空间,
  Partition par_RJEMP381_eincome_2 values less than(103) tablespace TAI_737,
  Partition par_RJEMP381_eincome_3 values less than (maxvalue) tablespace TDI_502
);

本地索引(local):

Create bitmap index 索引名 on 建索引的表(建索引的字段) local
(
  partition 分区命名  tablespace 第几个索引表空间,
  Partition stuno_RJSTU081_2_p  tablespace TDI_846,
  Partition stuno_RJSTU081_3_p  tablespace TJI_744
);

5、监控索引并维护数据:

alter index 题目要求索引名 monitoring usage;  //监视索引的使用
select * from 题目要求索引名的表名 where 查询条件;
select * from v$object_usage;  查看监视情况
alter index 题目要求索引名 nomonitoring usage;

修改:

开始监控:alter index index_name monitoring usage;
检查使用状态:select * from v$object_usage;
停止监控:alter index index_name nomonitoring usage;
drop index 索引名;
drop tablespace 表空间名;
清空表记录:
truncate table 表名;
查某个表上的索引
select * from user_indexes where table_name='';
查索引在哪列
select * from user_ind_columns where table_name='';
查询分区索引的信息
col INTERVAL_SUBPARTITION for a30
col INDEX_NAME for a30
col TABLE_NAME for a30
select * from user_part_indexes;
select * from dba_data_files; //查位置+实验6.7
select * from dba_temp_files;    //查询临时表空间位置
select * from dba_tablespaces;   //看块大小
改分区名
alter index ind_emp2_name rename partition    to    ;
监视索引的使用
alter index   monitoring usage;
查看监视情况
select * from v$object_usage;

维护数据(647001):

conn system/647001
truncate table RJPAR671;
insert into RJPAR671 values('1','00','类别1',to_date('2010-01-01','yyyy-mm-dd'),10,'6','001');
insert into RJPAR671 values('2','01','类别2',to_date('2010-01-02','yyyy-mm-dd'),20,'5','002');
insert into RJPAR671 values('3','02','类别3',to_date('2013-01-03','yyyy-mm-dd'),30,'4','003');
insert into RJPAR671 values('4','03','类别4',to_date('2013-01-04','yyyy-mm-dd'),40,'3','004');
insert into RJPAR671 values('5','04','类别5',to_date('2022-01-05','yyyy-mm-dd'),50,'2','005');
insert into RJPAR671 values('6','05','类别6',to_date('2022-01-06','yyyy-mm-dd'),60,'1','006');

truncate table RJEMP882;
insert into RJEMP882 values('1','名字1','工种1',to_date('2010-01-01','yyyy-mm-dd'),100,'名字5','001');
insert into RJEMP882 values('2','名字2','工种2',to_date('2010-01-02','yyyy-mm-dd'),200,'名字4','002');
insert into RJEMP882 values('3','名字3','工种3',to_date('2013-01-03','yyyy-mm-dd'),300,'名字3','003');
insert into RJEMP882 values('4','名字4','工种4',to_date('2013-01-04','yyyy-mm-dd'),400,'名字2','004');
insert into RJEMP882 values('5','名字5','工种5',to_date('2022-01-05','yyyy-mm-dd'),500,'名字1','005');

truncate table RJSTU303;
insert into RJSTU303(s_id,s_name,s_city,s_enroll,s_score,s_monitor,s_dept) values('1','姓名1','地区1',to_date('2010-01-01','yyyy-mm-dd'),100,'5','001');
insert into RJSTU303(s_id,s_name,s_city,s_enroll,s_score,s_monitor,s_dept) values('2','姓名2','地区2',to_date('2010-01-02','yyyy-mm-dd'),200,'4','002');
insert into RJSTU303(s_id,s_name,s_city,s_enroll,s_score,s_monitor,s_dept) values('3','姓名3','地区3',to_date('2013-01-03','yyyy-mm-dd'),300,'3','003');
insert into RJSTU303(s_id,s_name,s_city,s_enroll,s_score,s_monitor,s_dept) values('4','姓名4','地区4',to_date('2013-01-04','yyyy-mm-dd'),400,'2','004');
insert into RJSTU303(s_id,s_name,s_city,s_enroll,s_score,s_monitor,s_dept) values('5','姓名5','地区5',to_date('2022-01-05','yyyy-mm-dd'),500,'1','005');

truncate table RJCOU804;//要截断的表是簇的一部分,我直接删表重来了
drop table RJCOU804;
insert into RJCOU804 values('1','课程1','种类1',to_date('2010-01-01','yyyy-mm-dd'),10,'5','001');
insert into RJCOU804 values('2','课程2','种类2',to_date('2010-01-02','yyyy-mm-dd'),20,'4','002');
insert into RJCOU804 values('3','课程3','种类3',to_date('2013-01-03','yyyy-mm-dd'),30,'3','003');
insert into RJCOU804 values('4','课程4','种类4',to_date('2013-01-04','yyyy-mm-dd'),40,'2','004');
insert into RJCOU804 values('5','课程5','种类5',to_date('2022-01-05','yyyy-mm-dd'),50,'1','005');

drop table RJSPEC835;
insert into RJSPEC835 values('1','名称1');
insert into RJSPEC835 values('2','名称2');
insert into RJSPEC835 values('3','名称3');
insert into RJSPEC835 values('4','名称4');
insert into RJSPEC835 values('5','名称5');
insert into RJSPEC835 values('6','名称6');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值