07-31-2023, 04:05 AM
You will have to do it in two steps:
1. Update the table so that there are no nulls in the column.
<!---->
UPDATE MyTable SET MyNullableColumn = 0
WHERE MyNullableColumn IS NULL
2. Alter the table to change the property of the column
<!---->
ALTER TABLE MyTable
ALTER COLUMN MyNullableColumn MyNullableColumnDatatype NOT NULL
1. Update the table so that there are no nulls in the column.
<!---->
UPDATE MyTable SET MyNullableColumn = 0
WHERE MyNullableColumn IS NULL
2. Alter the table to change the property of the column
<!---->
ALTER TABLE MyTable
ALTER COLUMN MyNullableColumn MyNullableColumnDatatype NOT NULL