How can I find all columns of a certain type (for example NTEXT) in all tables in a SQL Server database?
I am looking for a SQL query.
You can use following query to return fields
SELECT table_name [Table Name], column_name [Column Name]
FROM information_schema.columns where data_type = 'NTEXT'
alter table [tablename] alter column [columnname] nvarchar(max). You can use LEN(..) etc. with nvarchar and not ntext.INNER JOIN INFORMATION_SCHEMA.TABLES t ON c.TABLE_NAME = t.TABLE_NAME AND t.TABLE_TYPE = 'BASE TABLE'I did use the following Statement to find all tables that could possibly hold binary-data/files.
SELECT
table_name
FROM
INFORMATION_SCHEMA.TABLES T
WHERE
T.TABLE_CATALOG = 'MyDatabase' AND
EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS C
WHERE
C.TABLE_CATALOG = T.TABLE_CATALOG AND
C.TABLE_SCHEMA = T.TABLE_SCHEMA AND
C.TABLE_NAME = T.TABLE_NAME AND
( C.DATA_TYPE = 'binary' OR
C.DATA_TYPE = 'varbinary' OR
C.DATA_TYPE = 'text' OR
C.DATA_TYPE = 'ntext' OR
C.DATA_TYPE = 'image' )
)