SQL 基础之索引、闪回、临时表(十八)

发布时间:2020-08-12 12:29:48 作者:yuri_cto
来源:网络 阅读:324

创建索引:

自动

– 创建 PRIMARY KEY

– 创建 UNIQUE KEY


手动

– CREATE INDEX 语句

– CREATE TABLE 语句


create table  语句中 create index


 create table new_emp (employee_id number(6) primary key using index

(create index emp_id_idx on

new_emp(employee_id)),

first_name varchar2(20),

last_name varchar2(25));


select index_name, table_name from user_indexes  where table_name = 'new_emp';


基于函数的索引


create index upper_dept_name_idx on dept2(upper(department_name));


select * from dept2 where upper(department_name) = 'SALES';


删除索引

使用 DROP INDEX 命令从数据字典中删除索引:

drop index index;

从数据字典中删除 UPPER_DEPT_NAME_IDX 索引:

drop index upper_dept_name_idx;

删除索引,您必须是索引的拥有者或者有 DROP ANY INDEX权限


drop table dept80 purge;


FLASHBACK TABLE  语句


表意外修改的修复工具:

– 表恢复到一个较早的时间点

– 优点:易用性、可用性、快速执行

– 执行到位(Is performed in place)


语法:

flashback table[schema.]table[,

[ schema.]table ]...

to { timestamp | scn } expr

[ { enable | disable } triggers ];


示例:

drop table emp2;

select original_name, operation, droptime from recyclebin;

flashback table emp2 to before drop;


临时表

创建临时表

create global temporary table cart on commit delete rows;


create global temporary table today_sales

on commit preserve rows as

select * from orders

where order_date = sysdate;


外部表

为外部表创建目录

创建 DIRECTORY对象,对应外部数据源所在的文件系统上的目录。

create or replace directory emp_diras '/.../emp_dir';

grant read on directory emp_dir to ora_21;


创建外部表

create table <table_name>

( <col_name> <datatype>, ... )

organization external

(type <access_driver_type>

default directory <directory_name>

access parameters

(...) )

location ('<location_specifier>')

reject limit [0 | <number> | unlimited];


使用ORACLE_LOADER 驱动创建外部表

create table oldemp (

fname char(25), lname char(25))

organization external

(type oracle_loader

default directory emp_dir

access parameters

(records delimited by newline

nobadfile

nologfile

fields terminated by ','

(fname position ( 1:20) char,

lname position (22:41) char))

location ('emp.dat'))

parallel 5

reject limit 200;


查询外部表

select * from oldemp

使用ORACLE_DATAPUMP驱动创建外部表:

create table emp_ext

(employee_id, first_name, last_name)

organization external

(

type oracle_datapump

default directory emp_dir

location

('emp1.exp','emp2.exp')

)

parallel

as

select employee_id, first_name, last_name

from employees;

推荐阅读:
  1. Oracle学习篇之SQL语句的优化
  2. 优化mysql sql和sql执行计划的步骤

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

sql 基础 索引

上一篇:1.--Goldgate单向复制(支持DDL)

下一篇:下一代CRM完美采用方案:添加智能语音接口?

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》