-- List all columns with varchar and nvarchar data type
SELECT OBJECT_NAME(col.OBJECT_ID) as [TableName], col.[name] as [ColName], typ.[name]
FROM sys.all_columns col
INNER JOIN sys.types typ
ON col.user_type_id = typ.user_type_id
WHERE col.user_type_id IN (167,231)
GO
Similarly you can use other usertypeid as shown below to find other datatypes.
bigint 127
binary 173
bit 104
char 175
datetime 61
decimal 106
float 62
image 34
int 56
money 60
nchar 239
ntext 99
numeric 108
nvarchar 231
real 59
smalldatetime 58
smallint 52
smallmoney 122
sql_variant 98
sysname 256
text 35
timestamp 189
tinyint 48
uniqueidentifier 36
varbinary 165
varchar 167
xml 241
Did you like this post?
|
|
|
||
|
|
|
|
|
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |




comments
4 Responses to "Find all columns with varchar and nvarchar datatypes"Excellent query. Thank you a lot. It was very helpful and saved me a lot of time.
All the best.
Nemanja
Thanks for this. The sys.* tables are a very powerful way to get at the structure of database tables and columns, but it's frequently difficult to figure out just how to get what you're looking for.
Type 36 = GUID
Post a Comment