Change a column to not allow nulls

后端 未结 2 551
悲&欢浪女
悲&欢浪女 2021-01-04 06:59

So I want to change a column in my SQL Server database to not allow nulls, but I keep getting an error. this is the sql statement I am using:

alter table [db         


        
2条回答
  •  清酒与你
    2021-01-04 08:00

    Clearly, the table has NULL values in it. Which you can check with:

    select *
    from mydatabase
    where WeekInt is NULL;
    

    Then, you can do one of two things. Either change the values:

    update mydatabase
        set WeekInt = -1
        where WeekInt is null;
    

    Or delete the offending rows:

    delete from mydatabase
        where WeekInt is null;
    

    Then, when all the values are okay, you can do the alter table statement.

提交回复
热议问题