SQL Server2008中通过SQL获取表结构

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用

新增数据用户,角色为public,映射到待获取表结构的数据库上,授与用户在该数据库上的身份为db_owner


执行如下SQL语句:

select   
syscolumns.name as [Name] ,  
systypes.name as [Type],  
syscolumns.length AS [Size],  
syscolumns.xprec As [Precision],   
ISNULL(syscolumns.scale, 0) AS [Scale],  
sys.extended_properties.value as [Mark],  
syscolumns.isnullable as [NULL],  
(Case when exists(  
select 1 from sysobjects  
 inner join sysindexes on sysindexes.name = sysobjects.name    
 inner join sysindexkeys on sysindexes.id = sysindexkeys.id and  sysindexes.indid = sysindexkeys.indid   
 where xtype='PK' and parent_obj = syscolumns.id      
 and sysindexkeys.colid = syscolumns.colid) then 1 else 0 end) AS [PK],  
(Case syscolumns.status when 128 then 1 else 0 end) AS [Identity]  
 from syscolumns    
 inner join systypes on (    
syscolumns.xtype = systypes.xtype    
 and systypes.name <>'_default_'     
 and systypes.name<>'sysname')    
 left outer join sys.extended_properties on (    
sys.extended_properties.major_id=syscolumns.id     
 and minor_id=syscolumns.colid)    
 where syscolumns.id = (select id from sysobjects where name='NDS_TFileForm')   
 order by syscolumns.colid  

标签: 数据库

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:观察者工具类NotificationUtil

下一篇:Android监控软键盘变化实例