Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Find All The Columns In Your SQL Server Database That Are Varchar(max) Or Nvarchar(max)

From Wiki

Jump to: navigation, search

To quickly find all the columns in your database that are either varchar(max) or nvarchar(max) you can use the information_schema.columns view. All you have to filter for is data_type has to be either varchar or nvarchar and character_maximum_length has to be =1

So first create these two tables

  1. create table Test321(id varchar(max),id2 int,id3 nvarchar(40))
  2.  
  3. create table Test456(id nvarchar(max),id2 int,id3 varchar(20))


And now when you run the following query

  1. select TABLE_NAME,COLUMN_NAME,DATA_TYPE
  2. from INFORMATION_SCHEMA.COLUMNS
  3. where DATA_TYPE in('varchar','nvarchar')
  4. and CHARACTER_MAXIMUM_LENGTH = -1

You get this as output

TABLE_NAME	COLUMN_NAME	DATA_TYPE
Test321		id		varchar
Test456		id		nvarchar


Contributed by: --SQLDenis 17:04, 27 April 2010 (GMT)

Part of SQL Server Admin Hacks

739 Rating: 2.9/5 (30 votes cast)