Add a constraint to a column on an Oracle table so that only positive values are allowed

constraintoracle

I'm not allowed to drop the table, or delete the columns.
The task is to add a constraint to a column possibly by using an ALTER statement so that it disallows any negative numbers. Is this possible?

I tried the following:

SQL> alter table SPEND_PLAN_DETAIL_VALUE modify (SP_DETAIL_VALUE_ID CHECK (SP_DETAIL_VALUE_ID > 0));

but this doesn't work.

Best Answer

To add a constraint you need to use add constraint:

alter table SPEND_PLAN_DETAIL_VALUE 
  add constraint check_detailvalue CHECK (SP_DETAIL_VALUE_ID > 0);

Online example