请问 asp.net(c#) 如何读取sqlserver表的字段名及数据类型?
1个回答
展开全部
Select
字段名=rtrim(b.name),
主键=CASE WHEN h.id IS NOT NULL THEN 'PK' ELSE '' END,
字段类型=type_name(b.xusertype)+CASE WHEN b.colstat&1=1 THEN '[ID(' + CONVERT(varchar, ident_seed(a.name))+','+CONVERT(varchar,ident_incr(a.name))+')]' ELSE '' END,
长度=b.length,
允许空=CASE b.isnullable WHEN 0 THEN 'N' ELSE 'Y' END,
默认值=isnull(e.text, ''),
字段说明=isnull(c.value, '')
FROM sysobjects a, syscolumns b
LEFT OUTER JOIN sysproperties c ON b.id = c.id AND b.colid = c.smallid
LEFT OUTER JOIN syscomments e ON b.cdefault = e.id
LEFT OUTER JOIN (Select g.id, g.colid FROM sysindexes f, sysindexkeys g Where (f.id=g.id)AND(f.indid=g.indid)AND(f.indid>0)AND(f.indid<255)AND(f.status&2048)<>0) h ON (b.id=h.id)AND(b.colid=h.colid)
Where (a.id=b.id)AND(a.id=object_id('要查询的表')) --要查询的表改成你要查询表的名称
orDER BY b.colid
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询