• SqlServer字段说明查询


    SELECT t.[name] AS 表名,c.[name] AS 字段名,cast(ep.[value] 
      as varchar(100)) AS [字段说明]
      FROM sys.tables AS t
      INNER JOIN sys.columns 
      AS c ON t.object_id = c.object_id
       LEFT JOIN sys.extended_properties AS ep 
      ON ep.major_id = c.object_id AND ep.minor_id = c.column_id WHERE ep.class =1 
      AND t.name='TableName'
    --快速查看表结构(比较全面的)
    SELECT  CASE WHEN col.colorder = 1 THEN obj.name
                      ELSE ''
                 END AS 表名,
            col.colorder AS 序号 ,
            col.name AS 列名 ,
            ISNULL(ep.[value], '') AS 列说明 ,
            t.name AS 数据类型 ,
            col.length AS 长度 ,
            ISNULL(COLUMNPROPERTY(col.id, col.name, 'Scale'), 0) AS 小数位数 ,
            CASE WHEN COLUMNPROPERTY(col.id, col.name, 'IsIdentity') = 1 THEN ''
                 ELSE ''
            END AS 标识 ,
            CASE WHEN EXISTS ( SELECT   1
                               FROM     dbo.sysindexes si
                                        INNER JOIN dbo.sysindexkeys sik ON si.id = sik.id
                                                                  AND si.indid = sik.indid
                                        INNER JOIN dbo.syscolumns sc ON sc.id = sik.id
                                                                  AND sc.colid = sik.colid
                                        INNER JOIN dbo.sysobjects so ON so.name = si.name
                                                                  AND so.xtype = 'PK'
                               WHERE    sc.id = col.id
                                        AND sc.colid = col.colid ) THEN ''
                 ELSE ''
            END AS 主键 ,
            CASE WHEN col.isnullable = 1 THEN ''
                 ELSE ''
            END AS 允许空 ,
            ISNULL(comm.text, '') AS 默认值
    FROM    dbo.syscolumns col
            LEFT  JOIN dbo.systypes t ON col.xtype = t.xusertype
            inner JOIN dbo.sysobjects obj ON col.id = obj.id
                                             AND obj.xtype = 'U'
                                             AND obj.status >= 0
            LEFT  JOIN dbo.syscomments comm ON col.cdefault = comm.id
            LEFT  JOIN sys.extended_properties ep ON col.id = ep.major_id
                                                          AND col.colid = ep.minor_id
                                                          AND ep.name = 'MS_Description'
            LEFT  JOIN sys.extended_properties epTwo ON obj.id = epTwo.major_id
                                                             AND epTwo.minor_id = 0
                                                             AND epTwo.name = 'MS_Description'
    WHERE   obj.name = 'TableName'--表名
    ORDER BY col.colorder ;
  • 相关阅读:
    solr jvm参数内存自动计算
    记一次使用Chrome修改useragent
    如何查看本机中已安装的.Net Framework版本
    经典实例 PetShop 4.0 For .NET 2.0 下载
    Web.Config配置节加密工具
    some command for Nokia IP 740
    JNCIP进阶OSPF MultiArea Configuration
    寒武纪
    Symantec AntiVirus Corporate Edition 10.0 Error: "Can't communicate with the Server Group..."
    心房客
  • 原文地址:https://www.cnblogs.com/kaynet/p/5802786.html
Copyright © 2020-2023  润新知