SQL Server Add, update, query table comment, field comment-related SQL

Source: Internet
Author: User


/******************* Field Add Comment *********************/if not exists (Selectc.value as Column_descriptionfrom sys.tables Ainner join Sys.columns B on b.object_id = A.object_idinner join sys.extended_properties C on c.major_id = B.object_id and c.minor_id = B.column_idwhere a.name = N ' table name ' and b.name=n ' field name ') EXEC sys.sp_addextendedproperty @name =n ' ms_description ' , @value =n ' field Notes ', @level0type =n ' SCHEMA ', @level0name =n ' dbo ', @level1type =n ' table ', @level1name =n ' name ', @level2type =n ' COLUMN ', @level2name =n ' field name ' EXEC sp_updateextendedproperty @name =n ' ms_description ', @value =n ' field comment ', @level0type =n ' SCHEMA ', @level0name =n ' dbo ', @level1type =n ' table ', @level1name =n ' name ', @level2type =n ' COLUMN ', @level2name =n ' field name '/*** Table Add Comment *********************/if not exists (Selecta.name,c.valuefrom sys.tables Ainner JOIN Sys.extended_properties C on c.major_id = a.object_id and Minor_id=0where a.name = N ' table name ') EXEC Sys.sp_addextendedproperty @name =n ' ms_description ', @value =n ' table Notes ', @level0type =n ' SCHEMA ', @level0naMe=n ' dbo ', @level1type =n ' table ', @level1name =n ' name ' EXEC sp_updateextendedproperty @name =n ' ms_description ', @value =n ' Table Notes ', @level0type =n ' SCHEMA ', @level0name =n ' dbo ', @level1type =n ' table ', @level1name =n ' name '/******************* Query comment Related sql***********************/--view table comments Selecta.name,c.valuefrom sys.tables Ainner JOIN sys.extended_properties C On c.major_id = a.object_id and Minor_id=0where a.name = N ' table name '--view field comments Selecta.name as table_name,b.name as Column_name,c . Value as Column_descriptionfrom sys.tables Ainner join sys.columns B on b.object_id = A.object_idleft JOIN sys.extended_p Roperties C on c.major_id = b.object_id and c.minor_id = b.column_idwhere a.name = N ' Luobo '

  

SQL Server Add, update, query table comment, field comment-related SQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.