sql server抓取表结构的语句

2018-07-13 08:50:30来源:编程学习网 阅读 ()

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

sql server 2008抓取方法:
---------------------------------------
 
SELECT
     表名 = Case When A.colorder=1 Then D.name Else '' End,
     表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End,
     字段序号 = A.colorder,
     字段名 = A.name,
     字段说明 = isnull(G.[value],''),
     标识 = Case When COLUMNPROPERTY( A.id,A.name,'IsIdentity')=1 Then '√'Else '' End,
     主键 = Case When exists(SELECT 1 FROM sysobjects Where xtype='PK' and parent_obj=A.id and name in (
                      SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = A.id AND colid=A.colid))) then '√' else '' end,
     类型 = B.name,
     占用字节数 = A.Length,
     长度 = COLUMNPROPERTY(A.id,A.name,'PRECISION'),
     小数位数 = isnull(COLUMNPROPERTY(A.id,A.name,'Scale'),0),
     允许空 = Case When A.isnullable=1 Then '√'Else '' End,
     默认值 = isnull(E.Text,'')
 FROM syscolumns A
 Left Join systypes B On A.xusertype=B.xusertype
 Inner Join sysobjects D On A.id=D.id and D.xtype='U' and D.name<>'dtproperties'
 Left Join syscomments E on A.cdefault=E.id
 Left Join sys.extended_properties G on A.id=G.major_id and A.colid=G.minor_id
 Left Join sys.extended_properties F On D.id=F.major_id and F.minor_id=0
 where d.name='person'
 Order By A.id,A.colorder 

标签:

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

上一篇:自动生成流水线号

下一篇:MySQL数据库常用命令小结

热门词条
热门标签