查看或添加修改sql表和字段描述

---查看表字段描述

SELECT
    A.name AS table_name,                 
    B.name AS column_name,              
    C.value AS column_description      
FROM sys.tables A
INNER JOIN sys.columns B
    ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C
    ON C.major_id = B.object_id
        AND C.minor_id = B.column_id
WHERE A.name = '表名'

---查看表描述

--添加表描述

EXECUTE sp_addextendedproperty N'MS_Description', N'优惠券表', N'schema', N'dbo', N'table', N'bs_customercoupon'

--修改表描述

EXECUTE sp_updateextendedproperty N'MS_Description', N'优惠券表', N'schema', N'dbo', N'table', N'bs_customercoupon'

--查看表描述

SELECT DISTINCT
    CONVERT(VARCHAR(50),tb.TABLE_NAME) AS table_name,--表名
    CONVERT(VARCHAR(50),tb.TABLE_SCHEMA) AS obj_name,--数据库引擎类型
    CONVERT(VARCHAR(50),ISNULL(f.value,'')) AS table_comment,--表描述
    CONVERT(VARCHAR(100),ISNULL(d.refdate,''),20)AS create_time--表创建时间
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
    LEFT JOIN information_schema.tables tb ON d.name=tb.TABLE_NAME
    WHERE tb.TABLE_CATALOG ='表名' AND tb.TABLE_NAME NOT LIKE 'q%'

你可能感兴趣的:(查看或添加修改sql表和字段描述)