Skip to content Skip to sidebar Skip to footer

In Sql How Do I Throw An Error When Updating 'not Null' Values In A Database Table

Looking to throw an error where the value i'm updating is a 'not null' value. For example. In below table, say I wanted to update Paul's lastname with 'Jackson'. The SQL should thr

Solution 1:

You need to do this with a trigger. Example trigger:

createtrigger schema.trigger_name
    before updateof last_name
    on tablename
    foreachrowbegin
    if :old.last_name isnotnullthen
        raise_application_error (-20100, 'Last name already has a value');
    end if;
end;
/

But this will stop any process that is running by raising a plsql error.

Post a Comment for "In Sql How Do I Throw An Error When Updating 'not Null' Values In A Database Table"