我可以在 SQL 服务器中删除一个 table 的列吗,它上面定义了一个非聚集索引

Can i drop a column of a table in SQL server which is having a non clustered index defined on it

我有一个 table 有大量记录。一些列定义了非聚集索引。

我们需要 alter/drop 几个定义了此类索引的列。

我已经直接 alter/dropped 列,但是 没有得到任何错误,例如:

Alter statement failed。它成功了。所以,我的问题是:

是否需要在将成为 dropped/altered 的列上删除非聚集索引?

why it did give any errors similar to case of constraints/keys defined on them ?

更新:

What incase of alteting a column for its size ? Is it supposed to throw any error ?

你的问题措辞对我来说有点奇怪,我无法完全理解你的问题...但这很容易测试你自己。

您不能删除具有索引的列,请参阅:

CREATE TABLE tempThing (id int IDENTITY(1,1) PRIMARY key, someValue varchar(50))
GO
CREATE INDEX idxTemp ON dbo.tempThing (someValue)
GO

然后:

ALTER TABLE dbo.tempThing DROP COLUMN someValue

给出错误:

Msg 5074, Level 16, State 1, Line 1 The index 'idxTemp' is dependent on column 'someValue'. Msg 4922, Level 16, State 9, Line 1 ALTER TABLE DROP COLUMN someValue failed because one or more objects access this column.

我刚试过这个:

create table #t1(i1 int, i2 int)
create index a1 on #t1(i1)


alter table #t1 drop column i1

失败 与消息 alter table drop column i1 failed because one or more objects access this`列。

您确定您有引用那些已删除列的索引并且已成功删除它们吗?