1、創(chuàng)建語句
成都創(chuàng)新互聯(lián)公司作為成都網(wǎng)站建設公司,專注重慶網(wǎng)站建設公司、網(wǎng)站設計,有關成都企業(yè)網(wǎng)站定制方案、改版、費用等問題,行業(yè)涉及柴油發(fā)電機等多個領域,已為上千家企業(yè)服務,得到了客戶的尊重與認可。
create table p(id number)
partition by range(id)
(partition p1 values less than(100) tablespace t1,
partition p2 values less than(200) tablespace t2,
partition p3 values less than(300) tablespace t3);
2、添加分區(qū)
alter table p add partition p4 values less than (400) tablespace t4;
3、清除分區(qū)數(shù)據(jù)
alter table p trunc partition p1;
4、刪除分區(qū)
alter table p drop partition p1;
根據(jù)數(shù)據(jù)表字段值的范圍進行分區(qū)。
創(chuàng)建完分區(qū)表后向表中添加一些數(shù)據(jù),declarenamevarchar2(10)。fractionnumber(5)。gradenumber(5)。inumber(8):=1。begin。foriin1。100000LOOP。當我們的查詢語句不指定分區(qū)的時候,如果分區(qū)字段出現(xiàn)在where條件之后,Oracle會自動根據(jù)字段值的范圍掃描響應的分區(qū)。
一.表分區(qū)策略
1.識別大表
采用ANALYZE TABLE語句進行分析,然后查詢數(shù)據(jù)字典獲得相應的數(shù)據(jù)量。
2.大表如何分區(qū)
可根據(jù)月份,季度以及年份等進行分區(qū);
3.分區(qū)的表空間規(guī)劃
要對每個表空間的大小進行估計
二.創(chuàng)建表分區(qū)
a.創(chuàng)建范圍分區(qū)的關鍵字是'RANGE'
1.范圍分區(qū)
create table ware_retail_part --創(chuàng)建一個描述商品零售的數(shù)據(jù)表
(
id integer primary key,--銷售編號
retail_date date,--銷售日期
ware_name varchar2(50)--商品名稱
)
partition by range(retail_date)
(
--2011年第一個季度為part_01分區(qū)
partition par_01 values less than(to_date('2011-04-01','yyyy-mm-dd')) tablespace TEMP01,
--2011年第二個季度為part_02分區(qū)
partition par_02 values less than(to_date('2011-07-01','yyyy-mm-dd')) tablespace TEMP01,
--2011年第三個季度為part_03分區(qū)
partition par_03 values less than(to_date('2011-10-01','yyyy-mm-dd')) tablespace TEMP01,
--2011年第四個季度為part_04分區(qū)
partition par_04 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace TEMP01
);
2.創(chuàng)建散列分區(qū)
3.組合分區(qū):
4.interval 分區(qū)
三.創(chuàng)建索引分區(qū)
索引分區(qū)分為本地索引分區(qū)和全局索引分區(qū),全局索引不反應基礎表的結(jié)構,要分區(qū)只能進行范圍分區(qū)。
創(chuàng)建索引分區(qū)要參照表分區(qū)
四.分區(qū)技術簡介
優(yōu)點:
1.減少維護工作量
2.增強數(shù)據(jù)的可用性
3.均衡I/O,提升性能
4.提高查詢速度
5.分區(qū)對用戶保持透明,用戶感覺不到分區(qū)的存在。
五,管理表分區(qū)
1.添加表分區(qū)
ALTER TABLE...ALTER PARATITION
2.合并表分區(qū)
3.刪除分區(qū)
ALTER TABLE...DROP PARTITION
刪除分區(qū)時,里面的數(shù)據(jù)也會被刪除。
-創(chuàng)建表和分區(qū)
create table sales--創(chuàng)建一個銷售記錄表
(
id number primary key,--記錄編號
goodsname varchar2(10),--商品名
saledate date--銷售日期
)
partition by range(saledate)--按照日期分區(qū)
(
--第一季度數(shù)據(jù)
partition part_sea1 values less than(to_date('2011-04-01','yyyy-mm-dd')) tablespace tbsp_1,
--第二季度數(shù)據(jù)
partition part_sea2 values less than(to_date('2011-07-01','yyyy-mm-dd')) tablespace tbsp_2,
--第三季度數(shù)據(jù)
partition part_sea3 values less than(to_date('2011-10-01','yyyy-mm-dd')) tablespace tbsp_1,
--第四季度數(shù)據(jù)
partition part_sea4 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace tbsp_2
);
--創(chuàng)建局部索引
create index index_3_4 on sales(saledate)
local(
partition part_seal tablespace tbsp_1,
partition part_sea2 tablespace tbsp_2,
partition part_sea3 tablespace tbsp_1,
partition part_sea4 tablespace tbsp_2
);
--并入分區(qū)
alter table sales merge partitions part_sea3,part_sea4 into partition part_sea4;
--重建局部索引
alter table sales modify partition part_sea4 rebuild unusable local indexes;
六.管理索引分區(qū)
刪除索引:DROP PARTITION
重建分區(qū):REBUILT PARTITION
更名索引分區(qū):RENAME PARTITION
分割索引分區(qū):SPLIT PARTITION
網(wǎng)站題目:oracle如何加分區(qū),oracle增加分區(qū)sql
鏈接URL:http://muchs.cn/article20/hcisjo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、品牌網(wǎng)站建設、關鍵詞優(yōu)化、外貿(mào)網(wǎng)站建設、服務器托管、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)