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)
?
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