概述

今天主要介绍SQLServer数据库如何快速查看表结构和获取相关信息。仅供参考。


全面查看表结构sql

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.name, 'Scale'), 0) AS 小数位数 , CASE WHEN COLUMNPROPERTY, col.name, 'IsIdentity') = 1 THEN '√' ELSE '' END AS 标识 , CASE WHEN EXISTS ( SELECT 1 FROM dbo.sysindexes si INNER JOIN dbo.sysindexkeys sik ON = AND = INNER JOIN dbo.syscolumns sc ON = AND = INNER JOIN dbo.sysobjects so ON = AND = 'PK' WHERE = col.id AND = col.colid ) THEN '√' ELSE '' END AS 主键 , CASE WHEN col.isnullable = 1 THEN '√' ELSE '' END AS 允许空 , ISNULL, '') 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 ep ON col.id = ep.major_id AND col.colid = ep.minor_id AND ep.name = 'MS_Description' LEFT JOIN epTwo ON obj.id = e AND e = 0 AND e = 'MS_Description' WHERE obj.name in ('表名') -- 表名 ORDER BY col.colorder;



后面会分享更多devops和DBA方面问题,感兴趣的朋友可以关注下!

1.《关于sql怎么快速查询,你需要知道这些分享sqlserver数据库如何快速查看表结构sql》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《关于sql怎么快速查询,你需要知道这些分享sqlserver数据库如何快速查看表结构sql》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/gl/3109971.html