Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1470

Re: Some questions about relational indexes and statistics in SS2005

From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver
Subject Re: Some questions about relational indexes and statistics in SS2005
Date 2013-05-07 21:26 +0200
Organization Erland Sommarskog
Message-ID <XnsA1B9DA262C7A3Yazorman@127.0.0.1> (permalink)
References <34bd78e8-b0d3-447c-a5de-88d35d6b6383@googlegroups.com>

Show all headers | View raw


 (rja.carnegie@gmail.com) writes:
> 1. A nonclustered index can "include" columns that are not part of 
>    the index key: can this be done with a nonclustered primary key
>    constraint index?

No.
 
> but the workaround might be to /not/ have a primary key, 
> but have a unique nonclustered index with included columns, which 
> does everything except display that it is the table's primary key, 

You could, but I have never seen the need. But, yeah, I could see the
scenario. 

> /or/, to create and then /disable/ the primary key index (if you 
> can do that), /and/ create the unique nonclustered index.

You can't disable the PK.

> 2. Will SQL Server ever automatically create a separate statistics group 
>    on columns that are already the key of a clustered or nonclustered 
>    index?  And, if so, should I consider improving the index so that 
>    it provides a satisfactory statistics group, and, how can I do that?

Not sure that I understand the question, but SQL Server always creates
statistics on the index columns. I have never heard "statistics group"
before, but maybe you mean multi-column statistics.
 
> (1) an index was created later than when the table was created, and a
> statistics group was already auto-created on the columns before the
> index was; 

Auto-stats are always single column statistics. Multi-column statistics
are always user-initiated, either through CREATE INDEX or CREATE
STATISTICS.

> (3) an index and a statistics group are on more than one column
> and have some of the same columns, or have columns in a different order;

Then they are different indexes and statistics. Orders matter in 
both.

> (4) a user-created statistics group has the same columns as an index.
> Maybe all at the same time.  All I know now is, they're there,
> and I think they're a bad sign.
 
If there is a user-defined statistics which has the same definition as
an index, that statistics is redundant and should be dropped.


-- 
Erland Sommarskog, Stockholm, esquel@sommarskog.se

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Some questions about relational indexes and statistics in SS2005 rja.carnegie@gmail.com - 2013-05-07 04:39 -0700
  Re: Some questions about relational indexes and statistics in SS2005 Erland Sommarskog <esquel@sommarskog.se> - 2013-05-07 21:26 +0200
    Re: Some questions about relational indexes and statistics in SS2005 rja.carnegie@gmail.com - 2013-05-09 14:45 -0700
      Re: Some questions about relational indexes and statistics in SS2005 Erland Sommarskog <esquel@sommarskog.se> - 2013-05-10 11:05 +0200
        Re: Some questions about relational indexes and statistics in SS2005 rja.carnegie@gmail.com - 2013-05-12 10:01 -0700
          Re: Some questions about relational indexes and statistics in SS2005 Erland Sommarskog <esquel@sommarskog.se> - 2013-05-12 19:22 +0200

csiph-web