iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >SQL 基础之索引、闪回、临时表(十八)
  • 645
分享到

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

2024-04-02 19:04:59 645人浏览 泡泡鱼
摘要

创建索引:自动– 创建 PRIMARY KEY– 创建 UNIQUE KEY手动– CREATE INDEX 语句– CREATE TABLE 语句create table  语句中 create

创建索引

自动

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


使用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;

您可能感兴趣的文档:

--结束END--

本文标题: SQL 基础之索引、闪回、临时表(十八)

本文链接: https://www.lsjlt.com/news/49084.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作