将SQL Server中所有表的列信息显示出来

2009-05-12 20:43:32来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

将SQL Server中所有表的列信息显示出来:

以下为引用的内容:

SELECT SysObjects.Name as tb_name, SysColumns.Name as col_name,

SysTypes.Name as col_type, SysColumns.Length as col_len, isnull

(SysProperties.Value,SysColumns.Name) as col_memo,
case when SysColumns.name in
(select 主键=a.name
FROM syscolumns a
inner join sysobjects b on a.id=b.id and

b.xtype='U' and b.name<>'dtproperties'
where 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
)))
and b.name=SysObjects.Name
)
then 1 else 0 end as is_key

FROM SysObjects,SysTypes,SysColumns

LEFT JOIN SysProperties ON (Syscolumns.Id = Sysproperties.Id AND

Syscolumns.Colid = Sysproperties.Smallid)

WHERE (Sysobjects.Xtype ='u' OR Sysobjects.Xtype ='v')
AND Sysobjects.Id = Syscolumns.Id AND SysTypes.XType = Syscolumns.XType

AND SysTypes.Name <> 'sysname' AND Sysobjects.

Name Like '%' ORDER By SysObjects.Name, SysColumns.colid

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:教你快速掌握SQL语言中游标的使用技巧

下一篇:使用SQL语句快速获取SQL Server数据字典

热门词条
热门标签