SQL Server查看全部的数据库、全部的表 以及表的描述

打印 上一主题 下一主题

主题 1518|帖子 1518|积分 4554

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. -- 查看所有的数据库
  2. select name from sys.databases order by name;
  3. -- 查看所有的表
  4. use [你的数据库名];
  5. -- select * from sys.objects order by type;
  6. -- select * from sys.objects where type = 'u';
  7. -- select object_id,name from sys.objects where type = 'u';
  8. select name 表名 from sys.objects where type = 'u';
  9. -- 查看表描述
  10. SELECT t.name 表名,prop.value 描述   
  11. FROM sys.tables t  
  12. LEFT JOIN sys.extended_properties prop
  13. ON prop.major_id=t.object_id AND prop.minor_id = 0 and prop.class = 1
  14. ORDER BY t.name;
  15. -- 查看表的信息
  16. use [你的数据库名];
  17. select
  18. col. name  as  ColumnName,
  19. col.max_length  as  DataLength,
  20. col.is_nullable  as  IsNullable,
  21. t. name  as  DataType,
  22. ep.value  as  Description,
  23. (
  24.      select  top  1 ind.is_primary_key  from  sys.index_columns ic
  25.      left  join  sys.indexes ind
  26.      on  ic.object_id=ind.object_id
  27.      and  ic.index_id=ind.index_id
  28.      and  ind. name  like  'PK_%'
  29.      where  ic.object_id=obj.object_id
  30.      and  ic.column_id=col.column_id
  31. )  as  IsPrimaryKey
  32. from  sys.objects obj
  33. inner  join  sys.columns col
  34. on  obj.object_id=col.object_id
  35. left  join  sys.types t
  36. on  t.user_type_id=col.user_type_id
  37. left  join  sys.extended_properties ep
  38. on  ep.major_id=obj.object_id
  39. and  ep.minor_id=col.column_id
  40. and  ep. name = 'MS_Description'
  41. where  obj. name ='[你的表名]';
复制代码
参考这里:SqlServer 之快速查看表结构 (表描述及字段说明).
查看SQL Server的表字段范例、长度、描述以及是否可为null.

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

干翻全岛蛙蛙

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表