SqlServer教程

SQL Server 表注释&列注释

本文主要是介绍SQL Server 表注释&列注释,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 添加表注释

-- 表加注释
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注释内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名'
--例如:
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'系统设置表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CM01_SYSTEM'

添加列注释

 -- 字段加注释
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注释内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'表名', @level2type=N'COLUMN',@level2name=N'字段名'

查询注释

--查询所有表及注释
SELECT
A.name ,C.value
FROM sys.tables A
LEFT JOIN sys.extended_properties C ON C.major_id = A.object_id
WHERE C.minor_id=0
group by A.name ,C.value


--查询表字段注释

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 = 'TABLE'

 

这篇关于SQL Server 表注释&列注释的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!