传统方法

  1. select * from (
  2. SELECT
  3. c.name 'ColumnName',
  4. t.Name 'DataType',
  5. c.max_length 'MaxLength',
  6. c.precision ,
  7. c.scale ,
  8. c.is_nullable 'IsNullable',
  9. ISNULL(i.is_primary_key, 0) 'IsPrimaryKey',
  10. c.is_identity IsIdentity
  11. FROM
  12. sys.columns c
  13. INNER JOIN
  14. sys.types t ON c.user_type_id = t.user_type_id
  15. LEFT OUTER JOIN
  16. sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
  17. LEFT OUTER JOIN
  18. sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
  19. WHERE
  20. c.object_id = OBJECT_ID('t_one_on_one')
  21. ) a
  22. inner join (
  23. select sc.name [Column],
  24. sep.value [Description]
  25. from sys.tables st
  26. inner join sys.columns sc on st.object_id = sc.object_id
  27. left join sys.extended_properties sep on st.object_id = sep.major_id
  28. and sc.column_id = sep.minor_id
  29. and sep.name = 'MS_Description'
  30. where st.name = 't_one_on_one'
  31. ) b
  32. on a.ColumnName=b.[Column]

快捷函数

  1. sp_help '表名'

参考

sp_help (Transact-SQL)