oracle alter table xxoo add constraint pk_xxoo primary key

oracle 添加 primary key 的步骤如下

-- drop table tmp_tt0 purge;
-- Create table
create table tmp_tt0
(
  c0 varchar2(100) default sys_guid() not null,
  c1 varchar2(100) not null,
  c2 varchar2(100)
) enable row movement monitoring initrans 10
;

create unique index pk_tmp_tt0 on tmp_tt0(c0) initrans 10 parallel 8 online;
alter table tmp_tt0 add constraint pk_tmp_tt0 primary key(c0) using index initrans 10 ;

create index ind_tmp_tt0_n1 on tmp_tt0(c1) initrans 10 parallel 8 online;


alter index pk_tmp_tt0     noparallel;
alter index ind_tmp_tt0_n1 noparallel;

其中 alter table tmp_tt0 add constraint pk_tmp_tt0 primary key(c0) using index initrans 10 ;
using index 使用 c0 列的唯一性索引。
如果该列上有唯一性索引,则使用。
如果该列上没有唯一性索引,则创建,索引的名字为约束的名字。

比如 alter table tmp_tt0 add constraint pk_tmp_tt0 primary key(c0) using index pk_tmp_tt0 initrans 10 ;

发布了710 篇原创文章 · 获赞 70 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/103685607