I have a table in which one of the column is set default to 0000 and the data type of of the column is number. I want to remove the default value and when a record is saved null should save on this column.
Asked
Active
Viewed 2,524 times
2 Answers
5
You could override default to NULL
:
ALTER TABLE tab_name MODIFY col_name DEFAULT NULL;
If columns was set as NOT NULL
then:
ALTER TABLE tab_name MODIFY col_name type_name DEFAULT NULL NULL;

Lukasz Szozda
- 162,964
- 23
- 234
- 275
-
1@OP Also, if you want it to be consistent consider a one-off update to make the current 0 records null. – Error_2646 Jul 17 '19 at 18:46
-
@Error_2646 Yes, I agree but it depends on requirements. – Lukasz Szozda Jul 17 '19 at 18:48
0
First, update current records:
update tab set col=null where col=0;
Then remove default value:
alter tab modify col default null;

fiveelements
- 3,649
- 1
- 17
- 16