日期:2014-05-19  浏览次数:20490 次

怎么查表有多少列,和列的详细资料
比如有表
create   table   c_cc
(
    C1   CHAR(20),
    C2   CHAR(40),
    c3   int,
    c4   datetime
)
我用SQL语句怎么查朝这个表中有多少列
每列的列名和类型是什么?



------解决方案--------------------

SELECT
表名=d.name,
字段名=a.name,
类型=b.name
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype= 'U '
and d.name= 'c_cc '
------解决方案--------------------
select c.name as '字段名 ', t.name as '数据类型 '
from syscolumns c, systypes t
where c.xtype = t.xtype
and c.id = object_id( '表名 ')
------解决方案--------------------
select a.name as 表名,b.name as 字段,c.name as 数据类型 from sysobjects a,syscolumns b,systypes c
where a.id=b.id and b.xtype=c.xtype and a.name=tablename