添加SQL字段说明

USE [xxx];
GO

;WITH cteCols AS (
    SELECT 
        c.name AS ColumnName
    FROM sys.columns c
    INNER JOIN sys.tables t ON c.object_id = t.object_id
    INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
    WHERE t.name = 'SSLPDT'
      AND s.name = 'dbo'
)
SELECT N'IF NOT EXISTS (SELECT 1 
    FROM fn_listextendedproperty(''MS_Description'',''schema'',''dbo'',''table'',''SSLPDT'',''column'',''' 
       + c.ColumnName + N''') 
    WHERE name=''MS_Description'')
BEGIN
    EXEC sys.sp_addextendedproperty 
         @name = N''MS_Description'', 
         @value = N''' + c.ColumnName + N''', 
         @level0type = N''Schema'', @level0name = N''dbo'', 
         @level1type = N''Table'',  @level1name = N''SSLPDT'', 
         @level2type = N''Column'', @level2name = N''' + c.ColumnName + N''';
END
'
FROM cteCols c
ORDER BY c.ColumnName;

  

posted @ 2024-12-27 10:34  ucdos2023  阅读(1)  评论(0编辑  收藏  举报