日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

oracle创建分区表

發(fā)布時間:2025/5/22 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle创建分区表 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在ORACLE里如果遇到特別大的表,可以使用分區(qū)的表來改變其應(yīng)用程序的性能。

以system身份登陸數(shù)據(jù)庫,查看 v$option視圖,如果其中Partition為TRUE,則支持分區(qū)功能;否則不支持。Partition有基于范圍、哈希、綜和三種類型。我們用的比較多的是按范圍分區(qū)的表。


在ORACLE里如果遇到特別大的表,可以使用分區(qū)的表來改變其應(yīng)用程序的性能。

以system身份登陸數(shù)據(jù)庫,查看 v$option視圖,如果其中Partition為TRUE,則支持分區(qū)功能;否則不支持。Partition有基于范圍、哈希、綜和三種類型。我們用的比較多的是按范圍分區(qū)的表。

我們以一個2001年開始使用的留言版做例子講述分區(qū)表的創(chuàng)建和使用:

1 、以system 身份創(chuàng)建獨(dú)立的表空間(大小可以根據(jù)數(shù)據(jù)量的多少而定)

create tablespace g_2000q4 datafile '/home/oradata/oradata/test/g_2000q4.dbf' size 50M default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

create tablespace g_2001q1 datafile '/home/oradata/oradata/test/g_2001q1.dbf' size 50M default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

create tablespace g_2001q2 datafile '/home/oradata/oradata/test/g_2001q2.dbf' size 50M default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

2 、用EXPORT工具把舊數(shù)據(jù)備份在guestbook.dmp中

把原來的guestbook表改名

alter table guestbook rename to guestbookold;

以guestbook 身份創(chuàng)建分區(qū)的表

create table guestbook(id number(16) primary key,username varchar2(64),sex varchar2(2),email varchar2(256),expression varchar2(128),content varchar2(4000),time date,ip varchar2(64) ) partition by range (time)(partition g_2000q4 values less than (to_date('2001-01-01','yyyy-mm-dd'))tablespace g_2000q4storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0), partition g_2001q1 values less than (to_date('2001-04-01','yyyy-mm-dd'))tablespace g_2001q1storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0),partition g_2001q2 values less than (to_date('2001-07-01','yyyy-mm-dd'))tablespace g_2001q2storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0));

(說明:分區(qū)的名稱可以和表空間的名稱不一致。這里是每個季度做一個分區(qū),當(dāng)然也可以每個月做一個分區(qū))

3、IMPORT導(dǎo)入數(shù)據(jù),參數(shù)ignore=y

4、分區(qū)表的擴(kuò)容:

到了2001 年下半年,建立新的表空間:

create tablespace g_2001q3 datafile '/home/oradata/oradata/test/g_2001q3.dbf' size 50m default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

為表添加新分區(qū)和表空間:

alter table guestbook add partition g_2001q3
values less than (to_date('2001-10-01','yyyy-mm-dd')
tablespace g_2001q3
storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0);

5、刪除不必要的分區(qū)

將2000年的數(shù)據(jù)備份(備份方法見 6、EXPORT 分區(qū)),將2000年的分區(qū)刪除。

alter table guestbook drop partion g_2000q4;

刪除物理文件

%rm /home/oradata/oradata/test/g_2000q4.dbf

6、EXPORT 分區(qū):

% exp guestbook/guestbook_password tables=guestbook:g_2000q4 rows=Y file=g_2000q4.dmp

7、IMPORT分區(qū):

例如在2001 年,用戶要查看2000 年的數(shù)據(jù),先創(chuàng)建表空間

create tablespace g_2000q4 datafile '/home/oradata/oradata/test/g_2000q4.dbf' size 50m default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

為表添加新分區(qū)和表空間:

alter table guestbook add partition g_2000q4
values less than (to_date('2001-01-01','yyyy-mm-dd')
tablespace g_2001q3
storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0);

導(dǎo)入數(shù)據(jù)

%imp guestbook/guestbook_password file=g_2000q4.dmp tables=(guestbook:g_2000q4) ignore=y

(說明:如果不指明導(dǎo)入的分區(qū),imp會自動按分區(qū)定義的范圍裝載數(shù)據(jù))

?

版權(quán)說明:文章轉(zhuǎn)自http://yinchunjian.javaeye.com/blog/680063

轉(zhuǎn)載于:https://www.cnblogs.com/maozhh/archive/2011/03/25/1995872.html

總結(jié)

以上是生活随笔為你收集整理的oracle创建分区表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。