Looking for a script to scan all tables in all SQL Server databases and list the columns which are large objects (TEXT, NTEXT, ,IMAGE VARCHAR(MAX), NVARCHAR(MAX), FILESTREAM, XML, VARBINARY).
while I probably can code this myself, I want a ready made script.
Bookmark this question. Show activity on this post. Looking for a script to scan all tables in all SQL Server databases and list the columns which are large objects (TEXT, NTEXT, ,IMAGE VARCHAR(MAX), NVARCHAR(MAX), FILESTREAM, XML, VARBINARY).
Large Objects (LOBs) are a set of datatypes that are designed to hold large amounts of data. A LOB can hold up to a maximum size ranging from 8 terabytes to 128 terabytes depending on how your database is configured. Storing data in LOBs enables you to access and manipulate the data efficiently in your application.
In a query editor, if you highlight the text of table name (ex dbo. MyTable) and hit ALT + F1 , you'll get a list of column names, type, length, etc.
select * from information_schema.columns where data_type in
('TEXT', 'NTEXT','IMAGE' ,'XML', 'VARBINARY')
or
(data_type = 'VARCHAR' and character_maximum_length = -1)
OR
(data_type = 'NVARCHAR' and character_maximum_length = -1)
Update Removed FILESTREAM from IN since the data_type is VARBINARY which is already captured
Try this
select * from information_schema.columns
where DATA_TYPE in('text','ntext','xml','image')
or (DATA_TYPE in('varchar','nvarchar','varbinary')
and CHARACTER_MAXIMUM_LENGTH = -1)
order by DATA_TYPE
filestream is stored as varbinary(max)
This will only capture varbinary(max), not varbinary(20) for example, if you also want that then move varbinary to the first condition, like this
select * from information_schema.columns
where DATA_TYPE in('text','ntext','xml','image','varbinary')
or (DATA_TYPE in('varchar','nvarchar')
and CHARACTER_MAXIMUM_LENGTH = -1)
order by DATA_TYPE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With