SQL$HELP72.HLB  —  ALTER  CONSTRAINT  Example
    This example shows how ALTER CONSTRAINT can be used to change the
    constraint attributes and add a comment to a constraint.

    SQL> set dialect 'sql99';
    SQL> attach 'file db$:mf_personnel';
    SQL>
    SQL> create table PERSON
    cont>     (last_name  char(20)
    cont>         constraint MUST_HAVE_LAST_NAME
    cont>             not null
    cont>             deferrable,
    cont>      first_name char(20),
    cont>      birthday   date
    cont>         constraint MUST_BE_IN_PAST
    cont>             check (birthday < current_date)
    cont>             not deferrable,
    cont>      constraint ALL_UNIQUE
    cont>         unique (last_name, first_name, birthday)
    cont>         deferrable initially immediate
    cont>     );
    SQL>
    SQL> show table (constraint) PERSON
    Information for table PERSON

    Table constraints for PERSON:
    ALL_UNIQUE
     Unique constraint
         Null values are considered distinct
     Table constraint for PERSON
     Evaluated on each VERB
     Source:
     UNIQUE (last_name, first_name, birthday)

    MUST_BE_IN_PAST
     Check constraint
     Column constraint for PERSON.BIRTHDAY
     Evaluated on UPDATE, NOT DEFERRABLE
     Source:
     CHECK (birthday < current_date)

    MUST_HAVE_LAST_NAME
     Not Null constraint
     Column constraint for PERSON.LAST_NAME
     Evaluated on COMMIT
     Source:
     PERSON.LAST_NAME NOT null

    Constraints referencing table PERSON:
    No constraints found

    SQL>
    SQL> alter constraint ALL_UNIQUE
    cont>     deferrable initially deferred;
    SQL>
    SQL> alter constraint MUST_HAVE_LAST_NAME
    cont>     comment is 'We must assume all persons have a name'
    cont>     not deferrable;
    SQL>
    SQL> alter constraint MUST_BE_IN_PAST
    cont>     deferrable initially immediate;
    SQL>
    SQL> show table (constraint) PERSON
    Information for table PERSON

    Table constraints for PERSON:
    ALL_UNIQUE
     Unique constraint
         Null values are considered distinct
     Table constraint for PERSON
     Evaluated on COMMIT
     Source:
     UNIQUE (last_name, first_name, birthday)

    MUST_BE_IN_PAST
     Check constraint
     Column constraint for PERSON.BIRTHDAY
     Evaluated on each VERB
     Source:
     CHECK (birthday < current_date)

    MUST_HAVE_LAST_NAME
     Not Null constraint
     Column constraint for PERSON.LAST_NAME
     Evaluated on UPDATE, NOT DEFERRABLE
     Comment: We must assume all persons have a name
     Source:
     PERSON.LAST_NAME NOT null

    Constraints referencing table PERSON:
    No constraints found

    SQL>
    SQL> commit;
Close Help