SQL server查看用户表的所有字段信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL server查看用户表的所有字段信息相关的知识,希望对你有一定的参考价值。
参考技术A select t1.id tabid,t1.name tabname,t2.name colname,t3.name datatype,t2.lengthfrom sysobjects t1,syscolumns t2,systypes t3
where t1.xtype='U'
and t1.id=t2.id
and t2.xtype=t3.xtype;
更详细的说明:
SELECT
表名 = d.name,
表说明 = isnull(f.value, ''),
字段序号 = a.colorder,
字段名 = a.name,
标识 = case when COLUMNPROPERTY(a.id, a.name, 'IsIdentity')= 1 then 'Y'else '' end,
主键 = case when exists(SELECT 1 FROM sysobjects where xtype = 'PK' and parent_obj = a.id and name in (
SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = a.id AND colid = a.colid))) then 'Y' else '' end,
类型 = b.name,
最大字节数 = a.length,
最大长度 = COLUMNPROPERTY(a.id, a.name, 'PRECISION'),
小数位数 = isnull(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0),
允许空 = case when a.isnullable = 1 then 'Y'else '' end,
默认值 = isnull(e.text, ''),
字段说明 = isnull(g.value, '')
FROM syscolumns a
left join systypes b
on a.xusertype = b.xusertype
inner join sysobjects d
on a.id = d.id and d.xtype = 'U' and d.name <> 'dtproperties'
left join syscomments e
on a.cdefault = e.id
left join sys.extended_properties g
on a.id = g.major_id and a.colid = g.minor_id
left join sys.extended_properties f
on d.id = f.major_id and f.minor_id = 0
order by d.name,a.colorder
以上是关于SQL server查看用户表的所有字段信息的主要内容,如果未能解决你的问题,请参考以下文章
[Microsoft][ODBC SQL Server Driver][SQL Server]拒绝了对对象'用户信息'(数据库'lianxi',所有者'db