背景:
生产上需要修改某个表的一个字段,将varchar修改为int类型
alter table xxxx alter column xxxx int;
实际上执行时报以下错误:
[Err] 42000 - [SQL Server]Object 'DF__cdis_file__contr__20900456' cannot be disabled or enabled. This action applies only to foreign key and check constraints. 42000 - [SQL Server]Could not enable or disable the constraint. See previous errors.
进去查看了表结构之后,发现有一个默认字段存在约束: DF__cdis_file__contr__20900456 ,因此不能修改字段信息
解决方法:
- 先将表字段的约束删除
- 修改表字段
- 重建字段约束
本文作者为lishengyu,转载请注明。