索引 视图
转自:https://www.cnblogs.com/diandixingyun/p/11608983.html https://www.cnblogs.com/diandixingyun/p/11609263.html
索引:
特点:对某列中的数据进行排序或归类,生成独立的索引表,查询条件包含该列时,Oracle 会自动引用该索引,先从索引表中查询出符合条件记录的 ROWID
作用:优化数据库查询的效率
缺点:
1、浪费空间来存储索引表
2、当数据量较少时,使用索引反而更慢
3、可提高查询效率,但数据增删改需更新索引
4、语法结构
create unique index 索引名称
on 原表名称(原列名称1,原列名称2)tablespace tab_name --tablespace表示索引存储的表空间pctfree n1 --索引块的空闲空间n1storage --存储块的空间 ( initial 64K --初始64k next 1M minextents 1 maxextents unlimited);create index cm_link_syon cm_link(device_id)
tablespace USERS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );5、查看索引: select * from all_indexes t where t.indexe.name='SYS_C0013374';
重命名索引:alter index old_name rename to new_name
删除索引:drop index name;
视图:
一、视图
1、语法:create or replace view 视图名称 as select 语句
2、特点:通过一张或多张基表,进行关联查询后组成的虚拟逻辑表
3、作用:部分用户只能查看部分字段,不显示敏感信息,保证数据安全
4、例子
CREATE OR REPLACE VIEW V_ALL_DS_INST AS
SELECT INST_ID,
INST_CODE,
INST_NAME,
CLASS_ID
FROM t_md_inst
where t_md_inst.APP_TYPE = 'DS'
UNION ALL
SELECT INST_ID,
INST_CODE,
INST_NAME,
CLASS_ID
FROM t_vr_inst_his
where t_vr_inst_his.APP_TYPE = 'DS';
5、查看视图 select * from 视图名称
6、授权 grante creat view to user_name

浙公网安备 33010602011771号