我正在使用SQL Server 2008
我知道如果更改视图定义,视图的索引将在不带偏见的情况下删除,也不会发出警告。我想知道是否有任何其他已知类似的自动更改索引,如果是这样,我在哪里可以阅读它们?
我的情况:
我们所有的开发者都表示他们没有搞乱指数。我们其中一个人可能会健忘。或说谎。或者某人可能已经改变了一些内容而没有仔细阅读警告信息。我不知道这是否是可以自动的,所以我希望你们能告诉我。
谢谢!
答案 0 :(得分:0)
我猜有人在钓鱼:) 此处的测试代码显示您无法在不首先删除索引的情况下更改PK的列数据类型:
create table dbo.worker
(
id int identity not null constraint PK_worker primary key,
name varchar(100) not null
);
-- Filtered index based in PK's primary index
create nonclustered index ix_worker
on dbo.worker (id)
where id < 3;
-- Try to change PK's column data type...
alter table dbo.worker
alter column id bigint;
SQL Server生成以下错误:
Msg 5074,Level 16,State 1,
第8行索引&#39; ix_worker&#39;取决于列&#39; id&#39;。
Msg 5074,Level 16,State 1,Line 8
对象&#39; PK_worker&#39;取决于列&#39; id&#39;。
Msg 5074,Level 16,State 1,Line 8
索引&#39; ix_worker&#39;取决于列&#39; id&#39;。
Msg 4922,Level 16,State 9,Line 8
ALTER TABLE ALTER COLUMN id失败,因为一个或多个对象访问此列。