Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does column order matter when creating statistics for Microsoft SQL Server?

The Database Engine Tuning Advisor has recommended the creation of some statistics for several of our queries. Turns out that some of these are the same just the column order is different in the CREATE STATISTICS command. For example:

CREATE STATISTICS [StatName1] ON [dbo].[table1]([column2], [column1])

CREATE STATISTICS [StatName2] ON [dbo].[table1]([column1], [column2])

are these the same or are they treated differently?

Along the same lines can I combine CREATE STATISTICS command for a given table? If the Advisor recommended 3 different stats on the same column for 3 different queries can I do a single create command for all 3 columns e.g.

CREATE STATISTICS [StatName1] ON [dbo].[table1]([column1], [column3])

CREATE STATISTICS [StatName2] ON [dbo].[table1]([column1], [column2])

into

CREATE STATISTICS [StatName1] ON [dbo].[table1]([column1], [column2], [column3])

Thanks

like image 337
Kyle Avatar asked May 31 '26 02:05

Kyle


1 Answers

multiple stats on the same column are useless. Only one is needed. order is irrelevant.

like image 152
Mladen Prajdic Avatar answered Jun 02 '26 17:06

Mladen Prajdic