Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15694

how sql server decide on what to create statistics ?

$
0
0

Hi,

I have a heap table.


IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Files]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Files](
 [FileId] [int] IDENTITY(1,1) NOT NULL,
 [FilePath] [nvarchar](255) NOT NULL,
 [FileType] [nvarchar](100) NOT NULL,
 [a] [int] NULL,
 CONSTRAINT [PK_Files] PRIMARY KEY NONCLUSTERED
(
 [FileId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Files__a__6166761E]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Files] ADD  DEFAULT ((7)) FOR [a]
END

 When I select :

SELECT * FROM sysindexes i  WHERE id=OBJECT_ID('Files')

I get 3 lines :

1) with name = null since this is a heap table

2) with name=PK_Files

3) with auto generated name on FilePath.

The question is : Why SQL server created statistics on FilePath and not on FileType  (both columns are mandatory string not indexed) ?


Regards, Asi Pesa


Viewing all articles
Browse latest Browse all 15694

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>