Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: OFFTOPIC Re: Naming DEFAULT constraints
Not sure if anybody will reply now but here goes, I hope so!
As stated I cannot rename the constraints once created, I need to be able to name them. Here is what I have done:
SQL> CREATE TABLE TEST1
2 ( TESTCOL1 NUMBER(9,0) DEFAULT 3 NOT NULL );
Table created.
1 SELECT CON.CONSTRAINT_NAME
2 FROM USER_CONSTRAINTS CON, USER_CONS_COLUMNS COL, USER_TAB_COLS
COLS
3 WHERE CON.TABLE_NAME = 'TEST1'
4 AND COL.COLUMN_NAME = 'TESTCOL1' 5 AND CON.TABLE_NAME = COL.TABLE_NAME 6 AND CON.TABLE_NAME = COLS.TABLE_NAME 7 AND COL.COLUMN_NAME = COLS.COLUMN_NAME 8 AND CON.CONSTRAINT_NAME = COL.CONSTRAINT_NAME9 AND COLS.DATA_DEFAULT IS NOT NULL
1 CREATE TABLE TEST1
2* ( TESTCOL1 NUMBER(9,0) NOT NULL)
SQL> /
Table created.
I can then do this:
1 ALTER TABLE TEST1
2 MODIFY
3* (TESTCOL1 NUMBER(9,0) DEFAULT 3)
SQL> /
Table altered.
But I want to be able to associate a name with this default 'constraint'.
I can rename it, so if we go back to the example above I can now do:
SQL> ALTER TABLE TEST1
2 RENAME CONSTRAINT SYS_C0060927
3 TO MyNamedConstraint;
Table altered.
SQL> SELECT CON.CONSTRAINT_NAME
2 FROM USER_CONSTRAINTS CON, USER_CONS_COLUMNS COL, USER_TAB_COLS
COLS
3 WHERE CON.TABLE_NAME = 'TEST1'
4 AND COL.COLUMN_NAME = 'TESTCOL1' 5 AND CON.TABLE_NAME = COL.TABLE_NAME 6 AND CON.TABLE_NAME = COLS.TABLE_NAME 7 AND COL.COLUMN_NAME = COLS.COLUMN_NAME 8 AND CON.CONSTRAINT_NAME = COL.CONSTRAINT_NAME9 AND COLS.DATA_DEFAULT IS NOT NULL 10 AND CON.CONSTRAINT_TYPE = 'C'; CONSTRAINT_NAME
Oracle 10.2.0.1.0
Thanks,
Paul Received on Mon Jan 29 2007 - 02:56:55 CST