博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SqlServer字段说明查询
阅读量:6479 次
发布时间:2019-06-23

本文共 2538 字,大约阅读时间需要 8 分钟。

SELECT t.[name] AS 表名,c.[name] AS 字段名,cast(ep.[value]   as varchar(100)) AS [字段说明]  FROM sys.tables AS t  INNER JOIN sys.columns   AS c ON t.object_id = c.object_id   LEFT JOIN sys.extended_properties AS ep   ON ep.major_id = c.object_id AND ep.minor_id = c.column_id WHERE ep.class =1   AND t.name='TableName'

 

--快速查看表结构(比较全面的)SELECT  CASE WHEN col.colorder = 1 THEN obj.name                  ELSE ''             END AS 表名,        col.colorder AS 序号 ,        col.name AS 列名 ,        ISNULL(ep.[value], '') AS 列说明 ,        t.name AS 数据类型 ,        col.length AS 长度 ,        ISNULL(COLUMNPROPERTY(col.id, col.name, 'Scale'), 0) AS 小数位数 ,        CASE WHEN COLUMNPROPERTY(col.id, col.name, 'IsIdentity') = 1 THEN '√'             ELSE ''        END AS 标识 ,        CASE WHEN EXISTS ( SELECT   1                           FROM     dbo.sysindexes si                                    INNER JOIN dbo.sysindexkeys sik ON si.id = sik.id                                                              AND si.indid = sik.indid                                    INNER JOIN dbo.syscolumns sc ON sc.id = sik.id                                                              AND sc.colid = sik.colid                                    INNER JOIN dbo.sysobjects so ON so.name = si.name                                                              AND so.xtype = 'PK'                           WHERE    sc.id = col.id                                    AND sc.colid = col.colid ) THEN '√'             ELSE ''        END AS 主键 ,        CASE WHEN col.isnullable = 1 THEN '√'             ELSE ''        END AS 允许空 ,        ISNULL(comm.text, '') AS 默认值FROM    dbo.syscolumns col        LEFT  JOIN dbo.systypes t ON col.xtype = t.xusertype        inner JOIN dbo.sysobjects obj ON col.id = obj.id                                         AND obj.xtype = 'U'                                         AND obj.status >= 0        LEFT  JOIN dbo.syscomments comm ON col.cdefault = comm.id        LEFT  JOIN sys.extended_properties ep ON col.id = ep.major_id                                                      AND col.colid = ep.minor_id                                                      AND ep.name = 'MS_Description'        LEFT  JOIN sys.extended_properties epTwo ON obj.id = epTwo.major_id                                                         AND epTwo.minor_id = 0                                                         AND epTwo.name = 'MS_Description'WHERE   obj.name = 'TableName'--表名ORDER BY col.colorder ;

 

转载于:https://www.cnblogs.com/kaynet/p/5802786.html

你可能感兴趣的文章
可以免费下载视频素材和模板网站汇总
查看>>
Q:图像太大,在opencv上显示不完全
查看>>
利用ItextPdf、core-renderer-R8 来生成PDF
查看>>
密码的校验.大小写字母,数字,特殊字符中的至少3种
查看>>
js滚动加载到底部
查看>>
memcache数据库和redis数据库的区别(理论)
查看>>
第三十九天
查看>>
Redis详解
查看>>
论程序员加班的害处
查看>>
基于HTML5的WebGL设计汉诺塔3D游戏
查看>>
WPF资料链接
查看>>
再次更新
查看>>
利用Windows自带的Certutil查看文件MD5
查看>>
开篇,博客的申请理由
查看>>
[JSOI2008]星球大战starwar BZOJ1015
查看>>
centos 7 部署LDAP服务
查看>>
iOS项目分层
查看>>
IntelliJ IDEA 注册码
查看>>
String字符串的截取
查看>>
Shell编程-环境变量配置文件
查看>>