Either this is impossible, or I can't write a good internet search.
I have a query to get the table and column information for our database:
SELECT t.name [table],
c.name [column]
FROM sys.tables t
LEFT JOIN sys.columns c on t.object_id = c.object_id
What I'd like to do is add in something like
(Select AVG(LEN(c.name)) from t.name) [AVG LEN]
I'd obviously build in some checks to only run on varchar for Len, and regular AVG for numerics, but that part would be easy. It is getting SQL to actually treat the names correctly that I'm struggling with.
For varChars, I'm aiming to get the min, avg, max, and mode lengths of the string values. I only listed the AVG to keep it simple. I'm also going to do some work with numeric values as well.
This way as I go to develop controls for these fields, I can better estimate the size to make the controls. I could do this column by column, but I'd like to be able to just be able to run one query and get my tables and columns in one nice chart.
Asked by CervonMi
(3 rep)
Feb 19, 2020, 03:11 AM
Last activity: Jul 3, 2022, 03:16 PM
Last activity: Jul 3, 2022, 03:16 PM