MSSQL中如何用SQL语句查询字段类型?

来源:百度知道 编辑:UC知道 时间:2024/05/13 00:47:40
请问写查询字段类型的SQL,多谢!
多谢各位的热心解答.
但我要查询的是"字段名的类型",是Int还是Char....并不是查询数据.

这个肯定得从系统表中查询了。

select a.name as [column],b.name as type
from syscolumns a,systypes b
where a.id=object_id('表名') and a.xtype=b.xtype

把“表名”替换成你要查看字段类型的表名,比如你要查看sysobjects表的各字段类型那么就是
select a.name as [column],b.name as type
from syscolumns a,systypes b
where a.id=object_id('sysobjects') and a.xtype=b.xtype

另外可以通过存储过程
exec sp_help 表名
来查看表各字段的信息,其中就包括字段类型。

select 想要找的文件名 from 数据库名
where 条件

回答完毕~!