I found this question on stackoverflow that almost answers my question: Find all columns of a certain type in all tables in a SQL Server database
However I need to find all fields of type nvarchar(max) specifically. If I try this:
SELECT table_name [Table Name], column_name [Column Name]
FROM information_schema.columns where data_type = 'nvarchar(max)'
It doesn't work and nothing is returned. If I try this:
SELECT table_name [Table Name], column_name [Column Name]
FROM information_schema.columns where data_type = 'nvarchar'
It works but there are hundreds of results and I only care about fields of max size. How do I select all nvarchar(max) fields specifically?
You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.
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).
Columns with data types like nvarchar(max), text, and ntext cannot be used in indexes.
The character_maximum_length
will be -1 for max
.
select
table_name as [Table Name]
, column_name as [Column Name]
from information_schema.columns
where data_type = 'nvarchar'
and character_maximum_length=-1
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