SqlServer 叢集索引重建後變換列位置統計資訊列名不變,

來源:互聯網
上載者:User

SqlServer 叢集索引重建後變換列位置統計資訊列名不變,

原本是使用叢集索引主鍵發現的,確認不是主鍵問題,是叢集索引問題。

version:Microsoft SQL Server 2008 R2 (SP1)


--建立測試表--drop table [TestTable]create table [dbo].[TestTable]([id] [int] not null,[name] [varchar](20) not null)go--插入資料insert into [TestTable]([id],[name])select id%10,left(name,20) from sys.sysobjectsgo--建立叢集索引([id] asc,[name] asc)create clustered index [pk_testtable] on [dbo].[TestTable]([id],[name])go

-- 查看統計資訊
-- dbcc show_statistics('[dbo].[TestTable]','pk_testtable')  



注意紅框的順序。現在重新建立叢集索引

--刪除叢集索引drop index [pk_testtable] on [dbo].[TestTable]go--建立叢集索引([name],[id])create clustered index [pk_testtable] on [dbo].[TestTable]([name],[id])go


刪除索引時,統計資訊會被刪除。現在再看名稱,索引已經改為([name],[id]),但統計資訊顯示的列 還是一樣!~bug?


--再看看統計資訊dbcc show_statistics('[dbo].[TestTable]','pk_testtable')  


統計資訊是正常的,只是頁面顯示的列名順序不一樣。

--查看索引使用方式,[name]是肯定使用索引了.select * from [TestTable] where [id] = 1select * from [TestTable] where [name] = 'A'


因為是索引,又不能刪除統計資訊,所以也改不了。

這雖然不是什麼嚴重性問題,但是奇怪,這些問題是否可修複?還不確定是否是ssms問題。

除了這個問題,還有中這功能  “更新這些列的統計資訊” 也是無效的!~





相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.