How to add a not null constraint on column containing null values

后端 未结 3 1074
孤街浪徒
孤街浪徒 2021-01-03 20:34

I have a table with a column that contains a few null values. I want to add a NOT NULL constraint on that column without updating the existing nulls to a non-nu

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 21:02

    ALTER TABLE table_name SET column_name = '0' WHERE column_name IS NULL;

    ALTER TABLE table_name MODIFY COLUMN(column_name NUMBER CONSTRAINT constraint_identifier NOT NULL);

    This is of course assuming that your column is a number but it's the same thing really, you would just change the '0' to a default value that isn't null.

提交回复
热议问题