Skip to Main Content
  • Questions
  • How to change the primary key name when I created Materialized view use the "with primary key" clause?

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, liu.

Asked: April 06, 2016 - 8:08 am UTC

Last updated: April 06, 2016 - 9:58 am UTC

Version: 12.1.0.2

Viewed 1000+ times

You Asked

In oracle 10g,when i create the mv with the primary key,the mv's primary key name is as the same as the source table,
but in 12c,it auto adds a prifix before the old name,how can i change it?



thanks a lot!!!

and Chris said...

You can change the name of a constraint using the "rename constraint" clause of "alter table", e.g.:

create table t (
  x int not null constraint pk primary key
);

select constraint_name from user_constraints
where  table_name = 'T'
and    constraint_type = 'P';

CONSTRAINT_NAME
---------------
PK

alter table t rename constraint pk to t_pk;

select constraint_name from user_constraints
where  table_name = 'T'
and    constraint_type = 'P';

CONSTRAINT_NAME
---------------
T_PK


http://docs.oracle.com/database/121/SQLRF/statements_3001.htm#i2103997

Is this answer out of date? If it is, please let us know via a Comment