D
D
Dmitry Petrov2020-02-29 14:38:55
SQL Server
Dmitry Petrov, 2020-02-29 14:38:55

Is there a solution for MSSQL that allows you to see statistics on how string columns are filled with data compared to column length?

There are many tables in the database with string fields. Some of them are nvarchar(max), some have a limited length. This was planned at the beginning of development because it was not known how long the values ​​in the columns would be.
Now we need to collect statistics to understand how the length of real data in columns differs from the maximum limit available for these columns, i.e. if the longest value in an nvarchar(100) column is 50 characters long, you should see those 50 characters. Well, in tabular form, or in the form of some kind of statistics (create statistics).
If it is possible to see the distribution in the form of a graph for each column, it would be generally excellent.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2020-02-29
@d-stream

Perverted, but effective option:
sys.objects - extract tables, for them - columns from sys.columns
for all [n]varchar not of maximum length - evaluate the given size and a fact like select max(len(desired column)) -> get " filling percentage"
But why is this all for var types ?? if nchar or char - you could still understand the logic, but for variable length which from birth have a sharpening for storing data of variable length.
p/s/ differences in the space occupied between a table with a varchar(5) field and with a varchar(100500) field with the same data of length 0..1 character - will be within the error
, the problem may be the opposite situation - when the table has a varchar(100) field ) but in fact there "need to fit" 150 characters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question