zoukankan      html  css  js  c++  java
  • sql server 快速查询某张表内的所有字段明细,包括大小、注释、类型等

    USE TestDB;


    SELECT 表名 = CASE
    WHEN A.colorder = 1 THEN
    D.name
    ELSE
    ''
    END,
    表说明 = CASE
    WHEN A.colorder = 1 THEN
    ISNULL(F.value, '')
    ELSE
    ''
    END,
    字段序号 = A.colorder,
    字段名 = A.name,
    字段说明 = ISNULL(G.[value], ''),
    标识 = CASE
    WHEN COLUMNPROPERTY(A.id, A.name, 'IsIdentity') = 1 THEN
    '√'
    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
    '√'
    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
    '√'
    ELSE
    ''
    END,
    默认值 = ISNULL(E.text, '')
    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
    WHERE D.name = 'Sys_FloorConfig' --如果只查询指定表,加上此条件
    ORDER BY A.id,
    A.colorder;

  • 相关阅读:
    讨论一下,乌云漏洞库的学习方法
    a
    asss
    密码重置
    SQL注入2
    起名字真难
    Header
    SQL注入1
    伪装者
    ofbiz 代码日记
  • 原文地址:https://www.cnblogs.com/Anthony518/p/11375440.html
Copyright © 2011-2022 走看看