Home » SQL & PL/SQL » SQL & PL/SQL » How to create Primary Key
How to create Primary Key [message #214870] Thu, 18 January 2007 05:28 Go to next message
Atif_Khan
Messages: 9
Registered: December 2006
Junior Member
Dear friends,

I removed the primary key from a table for some task using

SQL> alter table OMS_CNSG_TRACK drop constraint CNSGTRK_CNSG_NO_PK;

Table altered.

Now I want to re-create that Primary Key. What should I run for that? I tried alter tablename insert constraint PK but that didnt work.
Re: How to create Primary Key [message #214874 is a reply to message #214870] Thu, 18 January 2007 05:38 Go to previous messageGo to next message
dmitry.nikiforov
Messages: 723
Registered: March 2005
Senior Member
http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_32a.htm#2054899

ALTER TABLE ... ADD CONSTRAINT ... PRIMARY KEY (<<col>>,<<col>>,...,<<col>>)

Rgds.
Re: How to create Primary Key [message #214875 is a reply to message #214870] Thu, 18 January 2007 05:38 Go to previous messageGo to next message
Cthulhu
Messages: 381
Registered: September 2006
Location: UK
Senior Member
Sorry, if you've dropped it, it's gone. You will have to recreate it from script, if you have one. If you don't, you'll have to work out from scratch what it was.
Re: How to create Primary Key [message #214877 is a reply to message #214875] Thu, 18 January 2007 05:47 Go to previous messageGo to next message
tahpush
Messages: 961
Registered: August 2006
Location: Stockholm/Sweden
Senior Member

Show us the script and error if it's not working for you

ALTER TABLE OMS_CNSG_TRACK
ADD CONSTRAINT CNSGTRK_CNSG_NO_PK
PRIMARY KEY
(COL1,COL2...);
Re: How to create Primary Key [message #214882 is a reply to message #214877] Thu, 18 January 2007 06:23 Go to previous messageGo to next message
Atif_Khan
Messages: 9
Registered: December 2006
Junior Member
tahpush wrote on Thu, 18 January 2007 05:47
Show us the script and error if it's not working for you

ALTER TABLE OMS_CNSG_TRACK
ADD CONSTRAINT CNSGTRK_CNSG_NO_PK
PRIMARY KEY
(COL1,COL2...);




Thanks a lot guys. tahpush solution worked for me.
Re: How to create Primary Key [message #214902 is a reply to message #214882] Thu, 18 January 2007 08:28 Go to previous message
ab_trivedi
Messages: 460
Registered: August 2006
Location: Pune, India
Senior Member
Hi Atif,

this is great that you have solved the problem but my suggestion to you for the next time you can have enable/diable feature with the constraint and use them.

Bye
Ashu
Previous Topic: how to use decode function in for loop
Next Topic: Want to copy/append data in one table to another
Goto Forum:
  


Current Time: Thu Dec 08 14:23:48 CST 2016

Total time taken to generate the page: 0.07107 seconds