Oracle primary KEY constraints and renaming of primary key indexes __oracle

Source: Internet
Author: User

Oracle version:
Sql> select * from V$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.6.0-production
Pl/sql Release 9.2.0.6.0-production
CORE 9.2.0.6.0 Production

TNS for 32-bit windows:version 9.2.0.6.0-production
Nlsrtl Version 9.2.0.6.0-production

****************************************************************
* * When you create a primary key for a table, if you do not specify a primary key name, Oracle automatically generates a PRIMARY key constraint with a name similar to "sys_c00421221."
* * Also, generate a primary key index with the same name. The following query:

sql> COL constraint name FORMAT A13
sql> COL Constraint type FORMAT A8
sql> COL table name FORMAT A4
sql> COL naming Format A14
Sql> COL index name FORMAT A13
sql> SELECT constraint_name constraint name, constraint_type constraint type, table_name table name, generated naming method, index_name index name
2 from User_constraints
3 WHERE table_name = ' PC59 ' and constraint_type = ' P ';

Constraint name constraint type table name naming method index name
------------- -------- ---- -------------- -------------
sys_c00421221 P PC59 generated NAME sys_c00421221

****************************************************************
* * If you want to rename a primary key constraint and a primary key index, you can use the following methods:

sql> ALTER TABLE pc59 RENAME CONSTRAINT sys_c00421221 to pk_pc59;

Table Altered

sql> ALTER INDEX sys_c00421221 RENAME to pk_pc59;

Index Altered

****************************************************************
* * Requery the database view to see that both the primary KEY constraint and the name of the primary key index have changed.
* * But the naming method has not changed.
* * If you specify a name when you generate a primary key for the table, the naming is user name, otherwise generated name.

sql> COL constraint name FORMAT A13
sql> COL Constraint type FORMAT A8
sql> COL table name FORMAT A4
sql> COL naming Format A14
Sql> COL index name FORMAT A13
sql> SELECT constraint_name constraint name, constraint_type constraint type, table_name table name, generated naming method, index_name index name
2 from User_constraints
3 WHERE table_name = ' PC59 ' and constraint_type = ' P ';

Constraint name constraint type table name naming method index name
------------- -------- ---- -------------- -------------
pk_pc59 P PC59 generated NAME pk_pc59

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.