Please help me how to write a Query to change the primary
key constraint from 1 attribute to another attribute in a
table

Answers were Sorted based on User's Feedback



Please help me how to write a Query to change the primary key constraint from 1 attribute to anoth..

Answer / dinesh a.

You can assing only one primary key on a table , so you
can't modify directoly one column to another , you need to
drop first one then create on another attribute.

SQL>ct constraint_name,constraint_type from user_constraints
where table_name='EMP' and constraint_type='P';

CONSTRAINT_NAME C
------------------------------ -
SYS_C00125220 P

SQL> alter table emp drop constraint SYS_C00125220;

sql> alter table any_table add constraint my_cons_nm
primary key(column_of_tab)

Is This Answer Correct ?    6 Yes 1 No

Please help me how to write a Query to change the primary key constraint from 1 attribute to anoth..

Answer / chandana

YOU CANNOT CHANGE THE CONSTRAINTS DIRECTLY ON A COLUMN.
FIRST DROP THE CONSTARINT U HAVE CREATED AND THEN USE ALTER
COMMAND TO ADD CONSTARINT TO THE CORRECT COLUMN.

Is This Answer Correct ?    3 Yes 0 No

Please help me how to write a Query to change the primary key constraint from 1 attribute to anoth..

Answer / manvendra

ALTER TABLE TABLE_NAME
MODIFY COLUMN (COLUMN2 PRIMARY KEY);

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More Oracle General Interview Questions

What query tells you how much space a tablespace named test is taking up, and how much space is remaining?

0 Answers   Infosys,


What is a Schema ?

6 Answers  


What is Hash Cluster ?

2 Answers  


What are the different editions of oracle?

0 Answers  


How to use subqueries with the exists operator in oracle?

0 Answers  


if you ctreate table identity

0 Answers  


What happens to indexes if you drop a table?

0 Answers  


Difference between oracle's plus (+) notation and ansi join notation?

0 Answers  


What are the components of Logical database structure of ORACLE database?

4 Answers  


Define Normalization with example?

1 Answers  


What are cursor?where are they used?

2 Answers  


What is an UTL_FILE.What are different procedures and functions associated with it?

1 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1808)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)