kyooryu
kyooryu

Reputation: 1509

TSQL - Get maximum length of data in every column in every table without Dynamic SQL

Is there a way to get maximum length of data stored in every column in the database? I have seen some solutions which used Dynamic SQL, but I was wondering if it can be done with a regular query.

Upvotes: 2

Views: 955

Answers (2)

alzaimar
alzaimar

Reputation: 4622

If you are talking about the length of particular data in and not the declared length of a column, I am afraid that is not achievable without dynamic SQL.

The reason is that there is only way to retrieve data, and that is the SELECT statement. This statement however requires an explicit column, which is part of the statement itself. There is nothing like

-- This does not work
select col.Data 
  from Table 
 where Table.col.Name='ColumnName'

So the answer is: No.

Upvotes: 0

steoleary
steoleary

Reputation: 9278

Yes, Just query the INFORMATION_SCHEMA.COLUMNS view for the database, you can get the information out from all columns of all tables in the database if you desire, see the following for more details:

Information_Schema - COLUMNS

Upvotes: 1

Related Questions