SQL Server: Checking the datatype of a column

user1274655 picture user1274655 · Apr 27, 2012 · Viewed 39.5k times · Source

How to check if a column in a table has a specific datatype?

For example, how to check if a column in SQL Server table is of datatype char(11)?

Answer

juergen d picture juergen d · Apr 27, 2012
select COLUMN_NAME 
from INFORMATION_SCHEMA.COLUMNS
where DATA_TYPE = 'char'
and CHARACTER_MAXIMUM_LENGTH = 11
and TABLE_NAME = 'your_table'

using syscolumns:

SELECT name FROM SYSCOLUMNS
where length = 11
and xtype = 175 --char type