cancel
Showing results for 
Search instead for 
Did you mean: 

GIVING CUSTOM NAME TO KEY CONSTRAINTS using SQL CREATE Statement.

Former Member
0 Kudos

Hi Friends,

I know when Creating Table we define Primary and Foriegn keys (With system generated Constraint names like _SYS_CONSTRAINT_xxxxx_#xx_#F0)

And also we can view them by using following  SQL Syntax

---For Primary key

SELECT * FROM “SYS”."CONSTRAINTS" WHERE SCHEMA_NAME = 'TEST';

---For foreign key

SELECT * FROM "SYS"."REFERENTIAL_CONSTRAINTS"WHERE SCHEMA_NAME = 'TEST';

Also we can assign names of these CONSTRAINTS if we they are created using ALTER COMMENDS.(Example given below)

ALTER TABLE Orders

ADD CONSTRAINT fk_PerOrders

FOREIGN KEY (P_Id)

REFERENCES Persons(P_Id)


NOTE:Here fk_PerOrders is the name of foreign key constraint given by me


Based on My knowledge we are able to define CONSTRAINT with CUSTOM NAMES only after creating tables by the use of ALTER TABLE.


My question Is Can we create CONSTRAINTS with CUSTOM NAMES while CREATING the TABLE itself.



regards


Nagarjuna

Accepted Solutions (0)

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos

The documentation is not lying on this one. It's not possible to provide custom names to constraints within the CREATE TABLE command.

You can do that only with the ALTER TABLE command.

No need to SHOUT or to abuse the text formatting...

Former Member
0 Kudos

ok sir thanks