美文网首页
SQL server查看用户表的所有字段信息

SQL server查看用户表的所有字段信息

作者: Quick_5413 | 来源:发表于2022-03-18 11:41 被阅读0次

    select t1.id tabid,t1.name tabname,t2.name colname,t3.name datatype,t2.length
    from 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查看用户表的所有字段信息

          本文链接:https://www.haomeiwen.com/subject/slpidrtx.html