I wanted to create an outline constraint for an alter key(NOT NULL + UNIQUE), but I think the NOT NULL constraint can’t be placed outline, therefore, I think I have to options:
- Outline constraint:
CHECK(attr IS NOT NULL) - In-line constraint
NOT NULL+ outline constraintUNIQUE(attr)
Is there any difference between set the in-line constraint NOT NULL to a column and add a constraint CHECK (column IS NOT NULL)?
Thanks in advance
Defining a column as
NOT NULLis the preferred approach. That will indicate in theDBA_TAB_COLS,ALL_TAB_COLS, andUSER_TAB_COLSdata dictionary view, for example, that the column is notNULLABLE. That would be the conventional approach as well so future developers are much more likely to expect thatNOT NULLconstraints are defined on columns that cannot beNULL.Just as you could define
UNIQUEconstraints along withNOT NULLconstraints rather than creatingPRIMARY KEYconstraints, you could defineCHECKconstraints rather thanNOT NULLconstraints. Both approaches will work in the same way from a functional standpoint. But the data dictionary views will display those approaches differently so tools that rely on the data dictionary may behave slightly differently. And the conventional approaches are much more likely to be something that future developers will see and expect rather than being surprised by.