Originally found using the clustered index primary key, confirming that it is not a primary key problem, is a clustered index problem.
Version:microsoft SQL Server R2 (SP1)
--Create a test table--drop table [testtable]create table [dbo]. [TestTable] ([ID] [int] not null,[name] [varchar] (+) NOT null) go--insert data inserts into [TestTable] ([id],[name]) Select Id%10,left (name, From sys.sysobjectsgo--Create a clustered index ([ID] asc,[name] ASC) Create clustered index [pk_testtable] on [dbo]. [TestTable] ([Id],[name]) go
--
View statistical information
- -DBCC SHOW_STATISTICS (' [dbo].[ TestTable] ', ' pk_testtable ')
Note The order of the red boxes. Now re-create the clustered index
--Delete the clustered index drop INDEX [pk_testtable] on [dbo]. [testtable]go--creates a clustered index ([name],[id]) Create clustered index [pk_testtable] on [dbo]. [TestTable] ([Name],[id]) go
When you delete an index, the statistics are deleted. Now look at the name, the index has been changed to ([Name],[id]), but the statistics show the same column! ~bug?
--and look at statistics DBCC SHOW_STATISTICS (' [dbo].[ TestTable] ', ' pk_testtable ')
Statistics are normal, except that the column names displayed in the page are not in the same order.
--View index usage, [name] is definitely used index. SELECT * FROM [TestTable] where [id] = 1select * FROM [testtable] where [name] = ' A '
Because it is an index, and can not delete statistics, so also can not change.
This is not a serious problem, but is it strange that these problems can be fixed? Not sure if it's the ssms issue.
In addition to this problem, there is also the function "Update these columns statistics" is also invalid! ~
SQL Server clustered index rebuilds post-transform column location statistics column name unchanged