温馨提示×

温馨提示×

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

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

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

发布时间:2020-08-12 12:29:48 阅读:346 作者:yuri_cto 栏目:数据库
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

创建索引:

自动

– 创建 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';

基于函数的索引

  • 基于函数的索引就是一个基于表达式的索引

  • 索引表达式由列、常量、SQL 函数和用户自定义函数构成的

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  语句

  • 一条语句就可以恢复到指定时间点。

  • 恢复表中的数据以及相关的索引和约束。

  • 可以根据某一时间点或者系统改变号(SCN) 来恢复表。

表意外修改的修复工具:

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

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

– 执行到位(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];

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;

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

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

AI

开发者交流群×