解决SQL Server删除字段报错The object ‘DF__CompanyTr__Creat__0CDAE408’ is dependent on column ‘Created’.

问题描述

当我试图删除一个含有默认值得字段时

ALTER TABLE CompanyTransactions DROP COLUMN Created

报错如下:

Msg 5074, Level 16, State 1, Line 2
The object ‘DF__CompanyTr__Creat__0CDAE408’ is dependent on column ‘Created’.
Msg 4922, Level 16, State 9, Line 2
ALTER TABLE DROP COLUMN Created failed because one or more objects access this column.

解决方案

在删除列之前,必须从列中删除约束,引用的名称是默认约束。

alter table CompanyTransactions drop constraint df__CompanyTr__Creat__0cdae408;
alter table CompanyTransactions drop column Created;

 

你可能感兴趣的:(C#,Sql,Server,sqlserver,sql,c#)