Generate auto name for primarykey
892655Jul 9 2012 — edited Jul 10 2012Hi.
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 ...