首页 > 技术文章 > 更改可以为空的列为非空

davidhou 2015-12-30 14:50 原文

历史遗留问题,某些字段中有默认值,但允许为空,且记录中有为空的数据。

直接更改为非空的话会报错,解决办法:

1. alter table test1 with nocheck add constraint ck_n3 check (n3 is not null)

  增加一个非空的约束但加上with nocheck

2.批量更改为空的记录为默认值

 

推荐阅读