Search code examples
sqloracle-databaseconstraintsddlnotnull

How to name the constraint when add NOT NULL on ALTER TABLE


ALTER TABLE ACTOR MODIFY FIRST_NAME VARCHAR2(45) NOT NULL;

I know have to set FIST_NAME to NOT NULL, but I don not know how to name this constraint.

The name of this constraint should be "CK_Fanme"


Solution

  • You can use

    ALTER TABLE actor MODIFY ( first_name CONSTRAINT not_null_first_name NOT NULL );
    

    and query to see the result through use of user_constraints data dictionary view such as

    SELECT constraint_name
      FROM user_constraints
     WHERE table_name = 'ACTOR'
    

    Demo