Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generate auto name for primarykey

892655Jul 9 2012 — edited Jul 10 2012
Hi.
I need to create primarykey programatically from c#.

My sql looks like this:

ALTER TABLE AAA
ADD CONSTRAINT AAA_PK PRIMARY KEY
+(+
COLUMN1
+, COLUMN2+
+, COLUMN3+
+)+
ENABLE;

The problem is that I don't know if primarykey's name is already taken so I need to run another query before that:
SELECT COUNT(CONSTRAINT_NAME) FROM USER_CONSTRAINTS WHERE CONSTRAINT_NAME = 'AAA_PK '

I don't want to run two queries every time i create a new PK and I don't matter how this PK will called so I'm wondering if there is an option to let Oracle generate new name by itslef.
Somthing like (pseudo code):
ADD CONSTRAINT * PRIMARY KEY ...
This post has been answered by Solomon Yakobson on Jul 9 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2012
Added on Jul 9 2012
4 comments
888 views