How can I drop a "not null" constraint in Oracle when I don't know the name of the constraint? How can I drop a "not null" constraint in Oracle when I don't know the name of the constraint? oracle oracle

How can I drop a "not null" constraint in Oracle when I don't know the name of the constraint?


alter table MYTABLE modify (MYCOLUMN null);

In Oracle, not null constraints are created automatically when not null is specified for a column. Likewise, they are dropped automatically when the column is changed to allow nulls.

Clarifying the revised question: This solution only applies to constraints created for "not null" columns. If you specify "Primary Key" or a check constraint in the column definition without naming it, you'll end up with a system-generated name for the constraint (and the index, for the primary key). In those cases, you'd need to know the name to drop it. The best advice there is to avoid the scenario by making sure you specify a name for all constraints other than "not null". If you find yourself in the situation where you need to drop one of these constraints generically, you'll probably need to resort to PL/SQL and the data-definition tables.


Try:

alter table <your table> modify <column name> null;


Just remember, if the field you want to make nullable is part of a primary key, you can't.Primary Keys cannot have null fields.