14

如何检查表中的列是否具有特定的数据类型?

例如,如何检查SQL Server表中的列是否属于数据类型char(11)

4

3 回答 3

20
select COLUMN_NAME 
from INFORMATION_SCHEMA.COLUMNS
where DATA_TYPE = 'char'
and CHARACTER_MAXIMUM_LENGTH = 11
and TABLE_NAME = 'your_table'

使用syscolumns

SELECT name FROM SYSCOLUMNS
where length = 11
and xtype = 175 --char type
于 2012-04-27T15:08:32.273 回答
3
select case when DATA_TYPE= 'char' then 'T' else 'F' end,    
case when CHARACTER_MAXIMUM_LENGTH = 11 then 'T' else 'F' end    
from INFORMATION_SCHEMA.COLUMNS     
where COLUMN_NAME = 'MY_COLUMN_NAME'     
and TABLE_NAME = 'MY_TABLE_NAME'
于 2013-12-20T10:55:20.497 回答
0

查询列数据类型的sql查询

ALTER TABLE table_name MODIFY COLUMN column_name data_type;
于 2020-08-25T17:21:19.407 回答