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 are the arithmetic operations?

0 Answers  


What happens to indexes if you drop a table?

0 Answers  


How to drop an existing view in oracle?

0 Answers  


What is the use of Control File ?

3 Answers  


How can you merge two tables in oracle?

0 Answers  






how to get count of tables in particular database in Oracle?

3 Answers  


Why do we need integrity constraints in a database?

0 Answers  


What is an oracle table?

0 Answers  


How to connect the oracle server as sysdba?

0 Answers  


How do you store pictures in a database?

0 Answers  


How to delete an existing row from a table in oracle?

0 Answers  


When do you get a .pll extension in oracle?

0 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)