SQL server 为表和字段添加表描述和字段描述
查看当前数据库中已存在描述的表与字段:
SELECT 表名 =
-- CASE when a.colorder=1 then
d.name
-- else '' end
,
表说明 =
-- CASE when a.colorder=1 then
ISNULL(f.value, '')
-- else '' END
,
字段序号=a.colorder,
字段名 = a.name ,
标识=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
主键=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (
SELECT name FROM sysindexes WHERE indid in(
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
))) then '√' else '' end,
类型=b.name,
占用字节数=a.length,
长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
允许空=case when a.isnullable=1 then '√'else '' end,
默认值=isnull(e.text,''),
字段说明 = ISNULL(g.[value], '')
FROM syscolumns a
LEFT JOIN systypes b ON a.xtype = 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
在查询分析器中执行上面的SQL,结果可以直接导出execl文件
添加表说明:
EXECUTE sp_addextendedproperty N'MS_Description','表说明',N'user',N'dbo',N'table',N'表名',NULL,NULL
删除表说明:
EXEC sp_dropextendedproperty N'MS_Description','user','dbo','table', '表名', NULL,NULL
添加字段说明:
EXECUTE sp_addextendedproperty N'MS_Description','字段说明内容',N'user',N'dbo',N'table',N'表名',N'column',N'字段名'
删除字段说明:
EXEC sp_dropextendedproperty N'MS_Description', 'user','dbo', 'table', '表名', 'column','字段名'
出处:https://blog.csdn.net/zhangyongze_z/article/details/84789821
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/14215895.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
posted on 2020-12-31 12:37 jack_Meng 阅读(2957) 评论(0) 编辑 收藏 举报