From surenkid, 1 Month ago, written in SQL.
Embed
  1. USE test  --指定要生成数据字典的数据库
  2. GO
  3.  
  4. SELECT  
  5. 表名=CASE WHEN a.colorder=1 THEN d.name ELSE '' END,
  6. 表说明=CASE WHEN a.colorder=1 THEN isnull(f.value,'') ELSE '' END,
  7. 字段序号=a.colorder,
  8. 字段名=a.name,
  9. 标识=CASE WHEN COLUMNPROPERTY(a.id,a.name,'IsIdentity')=1 THEN '√'ELSE '' END,
  10. 主键=CASE WHEN EXISTS(SELECT 1 FROM sysobjects WHERE xtype='PK' AND name IN (
  11.   SELECT name FROM sysindexes WHERE indid IN(
  12.    SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
  13.    ))) THEN '√' ELSE '' END,
  14. 类型=b.name,
  15. 占用字节数=a.length,
  16. 长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
  17. 小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
  18. 允许空=CASE WHEN a.isnullable=1 THEN '√'ELSE '' END,
  19. 默认值=isnull(e.text,''),
  20. 字段说明=isnull(g.[VALUE],'')
  21. FROM syscolumns a
  22. LEFT JOIN systypes b ON a.xtype=b.xusertype
  23. INNER JOIN sysobjects d ON a.id=d.id AND d.xtype='U' AND d.name<>'dtproperties'
  24. LEFT JOIN syscomments e ON a.cdefault=e.id
  25. LEFT JOIN sys.extended_properties g ON a.id=g.major_id AND a.colid=g.minor_id
  26. LEFT JOIN sys.extended_properties f ON d.id=f.major_id AND f.minor_id =0
  27. --where d.name='要查询的表' --如果只查询指定表,加上此条件  
  28. ORDER BY a.id,a.colorder