先使字段col为空的都填上默认值 ‘0’:
update yourtable set col=0 where col is null
然后再col字段上加not null约束:
alter table yourtable modify column_name datatype not null;
update yourtable set col=0 where col is null
然后再col字段上加not null约束:
alter table yourtable modify column_name datatype not null;
数据库操作:设置默认值并添加字段约束
本文介绍如何使用SQL更新语句为数据库表中空字段设置默认值,并添加NOT NULL约束,确保数据完整性和一致性。
6万+

被折叠的 条评论
为什么被折叠?



