首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

如何查表有多少列,和列的详细资料

2012-01-30 
怎么查表有多少列,和列的详细资料比如有表createtablec_cc(C1CHAR(20),C2CHAR(40),c3int,c4datetime)我用S

怎么查表有多少列,和列的详细资料
比如有表
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

热点排行