列出SQL SERVER数据库所有表信息的SQL语句


  本文标签:SQL语句

  下面为您介绍的是列出SQL SERVER 数据库所有表信息的SQL语句,该SQL语句供您参考,希望对您学习SQL语句能有所启迪  。

  1. select    
  2.  
  3.       ( case when a.colorder = 1 then d.name else  end ) 表名,    
  4.        a.colorder 字段序号,    
  5.  
  6.        a.name 字段名,    
  7.       ( case when COLUMNPROPERTY (a.id,a.name,isidentity) = 1 then √ else  end ) 标识  
  8.       ( case when (     
  9.  
  10. select count(*) from sysobjects    
  11.  
  12. where name in (    
  13.  
  14. select name from sysindexes    
  15.  
  16. where (id = a.id ) and ( indid in    
  17.  
  18. (select indid from sysindexkeys where   
  19.  
  20. id = a.id ) and ( colid in (    
  21.  
  22. select colid from syscolumns    
  23.  
  24. where ( id = a.id ) and ( name = a.name ))))))    
  25.  
  26. and ( xtype =PK)) > 0 then √ else  end ) 主键,    
  27.  
  28. b.name 类型,    
  29.  
  30. a.length 字节数,    
  31.  
  32. COLUMNPROPERTY ( a.id,a.name ,PRECISION ) as 长度,    
  33.  
  34. isnull ( COLUMNPROPERTY ( a.id,a.name ,Scale),0) as 小数位数,    
  35.  
  36. (case when a.isnullable = 1 then √ else  end ) 允许空,    
  37.  
  38. isnull ( e.text,) 默认值,    
  39.  
  40. isnull (g.[value], ) as 字段说明    
  41.  
  42. from syscolumns a left join systypes b    
  43.  
  44. on a.xtype = b.xusertype    
  45.  
  46. inner join sysobjects d    
  47.  
  48. on a.id = d.id and d.xtype=U and d.name <> dtproperties   
  49.  
  50. left join syscomments e    
  51.  
  52. on a.cdefault = e.id    
  53.  
  54. left join sysproperties g    
  55.  
  56. on a.id = g.id and a.colid = g.smallid    
  57.  
  58. order by a.id ,a.colorder   
  59.