关于分区表创建主键

[复制链接]
查看11 | 回复4 | 2012-6-20 17:38:14 | 显示全部楼层 |阅读模式
今天做测试,创建分区表。表建好后创建索引,结果报错了。
create table t_login
(
id number ,
user_id varchar2(32) not null ,
gmt_view date
)
tablespace testsp
partition by range(gmt_view)
(
partition butl_060501 values less than (to_date('2006-05-01','yyyy-mm-dd')) tablespace testsp,
partition butl_060510 values less than (to_date('2006-05-10','yyyy-mm-dd')) tablespace testsp,
partition butl_060515 values less than (to_date('2006-05-15','yyyy-mm-dd')) tablespace testsp
);
alter table t_login add constraint pk_u_login primary key (id) using index tablespace testsp local;
*
第 1 行出现错误:
ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集
那就是说主键必须包含分区字段!!!如果不需要分区字段怎么创建索引呢?
我做了个测试,就是创建表的时候用以下语句:
create table t_login
(
id number ,
user_id varchar2(32) not null ,
gmt_view date ,
CONSTRAINT PRIKEY_test UNIQUE(id) USINGINDEX)
tablespace testsp
partition by range(gmt_view)
(
partition butl_060501 values less than (to_date('2006-05-01','yyyy-mm-dd')) tablespace testsp,
partition butl_060510 values less than (to_date('2006-05-10','yyyy-mm-dd')) tablespace testsp,
partition butl_060515 values less than (to_date('2006-05-15','yyyy-mm-dd')) tablespace testsp
);
创建成功后,然后再到pl/sql里把这个KEY的类型改成PRIMARY就成功了。
呵呵,这样做是不是太麻烦了,谁有更好的方法么?
[ 本帖最后由 听海★蓝心梦 于 2009-10-10 17:56 编辑 ]
回复

使用道具 举报

千问 | 2012-6-20 17:38:14 | 显示全部楼层
create table t_login
(
id number ,
user_id varchar2(32) not null ,
gmt_view date ,
CONSTRAINT PRIKEY_test primary key(id) USINGINDEX)
tablespace test01
partition by range(gmt_view)
(
partition butl_060501 values less than (to_date('2006-05-01','yyyy-mm-dd')) tablespace test01,
partition butl_060510 values less than (to_date('2006-05-10','yyyy-mm-dd')) tablespace test01,
partition butl_060515 values less than (to_date('2006-05-15','yyyy-mm-dd')) tablespace test01
);
这样也可以,是不是因为不能加local关键字啊?
回复

使用道具 举报

千问 | 2012-6-20 17:38:14 | 显示全部楼层
因为有local索引
回复

使用道具 举报

千问 | 2012-6-20 17:38:14 | 显示全部楼层
需要根据分区字段来区分索引创建在哪个表空间上
回复

使用道具 举报

千问 | 2012-6-20 17:38:14 | 显示全部楼层
原帖由 jlliuyi 于 2009-10-10 18:22 发表
需要根据分区字段来区分索引创建在哪个表空间上

不指定表空间就没这个错?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行