With SQL Server 2016, I have come to know some of the restrictions which were applicable earlier are no longer the limits to look for. In one such experimentation is what I stumbled upon the blog post: SQL SERVER – Fix: Error: Msg 1904, Level 16 The statistics on table has 33 column names in statistics key list. The maximum limit for index or statistics key column list is 32.
I thought having 32 columns itself was something far too many but to my surprise when I used the same script from the blog to just realize how this error was not popping up.
I went into a mode of exploration to find when the error would pop-up. The script this time was:
DROP DATABASE IF EXISTS TestDB GO CREATE DATABASE TestDB GO USE TestDB GO CREATE TABLE Test1 (ID1 INT, ID2 INT, ID3 INT, ID4 INT, ID5 INT, ID6 INT, ID7 INT, ID8 INT, ID9 INT, ID10 INT, ID11 INT, ID12 INT, ID13 INT, ID14 INT, ID15 INT, ID16 INT, ID17 INT, ID18 INT, ID19 INT, ID20 INT, ID21 INT, ID22 INT, ID23 INT, ID24 INT, ID25 INT, ID26 INT, ID27 INT, ID28 INT, ID29 INT, ID30 INT, ID31 INT, ID32 INT, ID33 INT, ID34 INT, ID35 INT, ID36 INT, ID37 INT, ID38 INT, ID39 INT, ID40 INT, ID41 INT, ID42 INT, ID43 INT, ID44 INT, ID45 INT, ID46 INT, ID47 INT, ID48 INT, ID49 INT, ID50 INT, ID51 INT, ID52 INT, ID53 INT, ID54 INT, ID55 INT, ID56 INT, ID57 INT, ID58 INT, ID59 INT, ID60 INT, ID61 INT, ID62 INT, ID63 INT, ID64 INT, ID65 INT) GO
And for creating the statistics, I have used the below:
CREATE STATISTICS [Stats_Test1] ON [dbo].[Test1] (ID1, ID2,ID3,ID4,ID5,ID6,ID7,ID8,ID9,ID10,ID11,ID12,ID13,ID14,ID15, ID16,ID17,ID18,ID19,ID20,ID21,ID22,ID23,ID24,ID25,ID26,ID27,ID28, ID29,ID30,ID31,ID32,ID33,ID34,ID35,ID36,ID37,ID38,ID39,ID40,ID41, ID42,ID43,ID44,ID45,ID46,ID47,ID48,ID49,ID50,ID51,ID52,ID53,ID54, ID55,ID56,ID57,ID58,ID59,ID60,ID61,ID62,ID63,ID64,ID65) GO
Msg 1904, Level 16, State 2, Line 21
The statistics ‘Stats_Test1’ on table ‘dbo.Test1’ has 65 columns in the key list. The maximum limit for statistics key column list is 64.
As you can see, now the maximum limit for statistics for key column list has been doubled to 64. So the new limit for the same has changed with SQL Server 2016. I am sure you are going to hit this limit if you are going to create an index or statistics having columns more than 64.
At this moment I would like to bring a note to Maximum Capacity Specifications for SQL Server page on MSDN for your reference because this is the root page for all these limits that one needs to be aware off. Have you ever hit this limit in your environments or scripts? Do let me know via comments.
Reference: Pinal Dave (https://blog.sqlauthority.com)