数据库教程:快速查看表结构 SQL server查看表注释以及字段注释表结构字段说明

DECLARE @tableName NVARCHAR(MAX);SET @tableName = N'UserIntegralExchange'; –表名!!! SELECT CASE WHEN col.colorder = 1 THEN obj.name ELSE '' END AS 表名 , …

declare @tablename nvarchar(max);
set @tablename = n’userintegralexchange’;   –表名!!!

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;

需要了解更多数据库技术:快速查看表结构 SQL server查看表注释以及字段注释表结构字段说明,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/626817.html

(0)
上一篇 2021年5月26日
下一篇 2021年5月26日

精彩推荐