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 is a read write transaction in oracle?

0 Answers  


 How to use an oracle sequence generator in a mapping?

0 Answers   Informatica,


What are the oracle differences between nvl and coalesce

0 Answers  


What privilege is needed for a user to create views in oracle?

0 Answers  


What is index in Oracle?

0 Answers   MCN Solutions,






What privilege is needed for a user to delete rows from tables in another schema?

0 Answers  


1) What is dense ranking? 2) Difference between Substring and Instring? 3) Case and Decode? 4) Pseudo column? 5) View vs Materialized views? 6) SQl performance tuning?

2 Answers   Accenture,


What is a sub query? What are its various types?

0 Answers  


What is a subquery?

0 Answers  


What is meant by redo log buffer ?

2 Answers  


Can we create more than one index on particular column?

1 Answers  


what are the different types of cursors? explain?

4 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • 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)