Connect with Facebook

Monday, December 01, 2008

Reusing Primary Key

I's working in development project. I was doing reuse, rename, drop, and create some tables a lot. And I like creating constraints manually with specific naming that fits me.

SQL> Alter Table YA_JUDUL_TEMA Rename Constraint PK_JUDUL_TABEL To PK_JUDUL_TEMA_DIsabled;

Elapsed: 00:00:00.04
SQL> alter table judul_tabel add constraint PK_judul_tabel primary key (id_judul);
alter table judul_tabel add constraint PK_judul_tabel primary key (id_judul)
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

Elapsed: 00:00:00.03


What object??
While renaming table for backing up and creating new one, I want to reuse the same constaints, say primary key. As a matter of fact that everythime I create primary key, Oracle automatically create index with the same name as constraints.

So, if I want to reuse that primary key name for the new table I need to rename to other, like wise the index must be rename axpliciltly.

Here are the script:



SQL> select * from user_indexes where table_name='YA_JUDUL_TEMA';

INDEX_NAME |INDEX_TYPE |TABLE_OWNER |TABLE_NAME |TABLE_TYPE
---------------|------------|------------|----------------|-----------
PK_JUDUL_TABEL |NORMAL |SISN |YA_JUDUL_TEMA |TABLE

SQL> alter index PK_JUDUL_TABEL rename to PK_JUDUL_Tema_disabled;

Index altered.


Bare Conslusion.

  1. Oracle unallowed user creating objects with the same name

  2. Index is object


0 comments:

Post a Comment