Search code examples
sqlsql-servert-sqlvarbinaryvarbinarymax

What is the T-SQL syntax for finding table/s in my SQL Server database which has a VARBINARY column type?


I have a database running on SQL Server 2012 and I need to locate the tables which have varbinary column type in them.

In fact, I need to retrieve some scanned documents which have been stored in the database. I have found one table called 'ScannedDocument' and it does have a varbinary column, called 'SCD_DOCIMAGE'. However, when I run the following:

Select * from ScannedDocument

, I don't get any results in the output window in SSMS.

My first guess is that the scanned documents I am looking for are not stored in this table. What would be the T-SQL syntax to locate all tables with varbinary columns?

Also, what would be the T-SQL syntax to retrieve the documents from that column once the correct table has been identified?


Solution

  • Take a peek at INFORMATION_SCHEMA.COLUMNS

    Select * From INFORMATION_SCHEMA.COLUMNS where data_type='varbinary'
    

    To Download or Save to Disk, this may help Script to save varbinary data to disk