SQL Server表和欄位的說明

來源:互聯網
上載者:User
1. 增加欄位說明EXEC sp_addextendedproperty
    'MS_Description',
    'some description',
    'user',
     dbo,
    'table',
     table_name,
    'column',
     column_name
  • Some Description , 是要增加的說明內容
  • table_name, 是表名
  • column_name , 是欄位名
2. 增加表的說明EXEC sp_addextendedproperty
    'MS_Description',
    'some description',
    'user',
     dbo,
    'table',
     table_name 參數說明同上 3. 取得欄位說明內容  
SQL Server 2000 SQL Server 2005 ( 包括 express)
SELECT
    [Table Name] = i_s.TABLE_NAME,
    [Column Name] = i_s.COLUMN_NAME,
    [Description] = s.value
FROM
    INFORMATION_SCHEMA.COLUMNS i_s
LEFT OUTER JOIN
    sysproperties s
ON
    s.id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME)
    AND s.smallid = i_s.ORDINAL_POSITION
    AND s.name = 'MS_Description'
WHERE
    OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0
    -- AND i_s.TABLE_NAME = 'table_name'
ORDER BY
    i_s.TABLE_NAME, i_s.ORDINAL_POSITION
SELECT
    [Table Name] = OBJECT_NAME(c.object_id),
    [Column Name] = c.name,
    [Description] = ex.value
FROM
    sys.columns c
LEFT OUTER JOIN
    sys.extended_properties ex
ON
    ex.major_id = c.object_id
    AND ex.minor_id = c.column_id
    AND ex.name = 'MS_Description'
WHERE
    OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0
    -- AND OBJECT_NAME(c.object_id) = 'your_table'
ORDER
    BY OBJECT_NAME(c.object_id), c.column_id

4. 取得表說明  

SELECT 表名 = case when a.colorder = 1 then d.name
                   else '' end,
       表說明 = case when a.colorder = 1 then isnull(f.value, '')
                     else '' end FROM syscolumns a
       inner join sysobjects d
          on a.id = d.id
             and d.xtype = 'U'
             and d.name <> 'sys.extended_properties'
       left join sys.extended_properties   f
         on a.id = f.major_id
            and f.minor_id = 0
Where (case when a.colorder = 1 then d.name else '' end) <>''
 

 

 

SELECT

        (case when a.colorder=1 then d.name else '' end) 表名,        a.colorder 欄位序號,        a.name 欄位名,       g.[value] AS 欄位說明FROM syscolumns a left join systypes bon a.xtype=b.xusertypeinner join sysobjects don a.id=d.id and d.xtype='U' and d.name<>'dtproperties'left join sys.extended_properties gon a.id=g.major_id AND a.colid = g.minor_idWHERE d.[name] <>'table_desc' --你要查看的表名,注釋掉,查看當前資料庫所有表的欄位資訊order by a.id,a.colorder
--建立表及描述資訊

create table 表(a1 varchar(10),a2 char(2))

--為表添加描述資訊
EXECUTE sp_addextendedproperty N'MS_Description', '人員資訊表', N'user', N'dbo', N'table', N'表', NULL, NULL

--為欄位a1添加描述資訊
EXECUTE sp_addextendedproperty N'MS_Description', '姓名', N'user', N'dbo', N'table', N'表', N'column', N'a1'

--為欄位a2添加描述資訊
EXECUTE sp_addextendedproperty N'MS_Description', '性別', N'user', N'dbo', N'table', N'表', N'column', N'a2'
--更新表中列a1的描述屬性:
EXEC sp_updateextendedproperty 'MS_Description','欄位1','user',dbo,'table','表','column',a1

--刪除表中列a1的描述屬性:
EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','表','column',a1

--刪除測試
drop table 表

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.