SQL: get max length of values in every table column

SQL to get max length of values in every table column

I had an issue to resolve once upon a time where data could not be loaded into a table because “string or binary data would be truncated”.

The target table had well over 50 columns with several million rows.

The only easy way to figure out what incoming data was longer than the specified schema was to implement the following SQL.


(Visited 132 times, 1 visits today)
  • CruisingTroll

    I have built something similar, although mine was initially built to ease building views on data from a cloud app provider (CRM software) that loves loves loves to include lots and lots of unused fields. As a result, I also returned the number of unique values in a field, so I could identify and drop the useless fields from the view.

    What I want to know is why, at least 10 years after people first called Microsoft out on this semi-useless error, MS STILL hasn’t included at least the blasted FIELD NAME of the offender in the error?