删除 有默认值的列

一开始我给表增加了一列(带默认值0),alter table 表名 add recruit_hung char(1) default('0')

当我想要删除那一列时

alter table 表名 drop column recruit_hung

报错

Msg 5074, Level 16, State 1, Line 1
'DF__basic_gra__recru__1487BE1F' 依赖于 列'recruit_hung'。
Msg 4922, Level 16, State 9, Line 1
由于一个或多个对象访问此列,ALTER TABLE DROP COLUMN recruit_hung 失败。

经过查询发现是他才能在依赖(默认值)要先删除依赖

alter table 表名 drop CONSTRAINT DF__basic_gra__recru__1487BE1F

然后执行

alter table 表名 drop column recruit_hung

成功了

猜你喜欢

转载自zwxiaole.iteye.com/blog/1598685