改变列滴指数

时间:2009-10-30 10:08:52

标签: sql sql-server sql-server-2005 indexing

我有一张桌子

CREATE TABLE table1(
 [classe] [char](30) NOT NULL,
 [code] [char](30) NOT NULL,
 [description] [varchar](255) NULL,
 [codelangue] [char](2) NULL
) ON [PRIMARY]

索引

CREATE NONCLUSTERED INDEX [table1_id1] ON [dbo].[table1] 
(
 [codelangue] ASC,
 [classe] ASC,
 [code] ASC
)
INCLUDE ( [description]) WITH (PAD_INDEX  = OFF, 
STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, 
IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, 
ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

当我这样做时

ALTER TABLE table1
ALTER COLUMN codelangue [char](2) NOT NULL

它会删除索引和相关的统计信息。

知道为什么吗?

2 个答案:

答案 0 :(得分:0)

ALTER TABLE table

我认为这应该是“table1”而不是“table”?

在我安装SQL Server 2005时,此代码会生成错误:

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

答案 1 :(得分:0)

不同的表(例如bob.table1而不是dbo.table1)或不同的数据库。

ALTER 不会在我熟悉的任何版本的SQL Server上执行