SQL Server查看所有的数据库、所有的表 以及表的描述

文章目录

sql 复制代码
-- 查看所有的数据库
select name from sys.databases order by name;


-- 查看所有的表
use [你的数据库名];
-- select * from sys.objects order by type;
-- select * from sys.objects where type = 'u';
-- select object_id,name from sys.objects where type = 'u';
select name 表名 from sys.objects where type = 'u';


-- 查看表描述
SELECT t.name 表名,prop.value 描述   
FROM sys.tables t  
LEFT JOIN sys.extended_properties prop 
ON prop.major_id=t.object_id AND prop.minor_id = 0 and prop.class = 1
ORDER BY t.name;


-- 查看表的信息
use [你的数据库名];
select
col. name  as  ColumnName,
col.max_length  as  DataLength,
col.is_nullable  as  IsNullable,
t. name  as  DataType,
ep.value  as  Description,
(
     select  top  1 ind.is_primary_key  from  sys.index_columns ic
     left  join  sys.indexes ind
     on  ic.object_id=ind.object_id
     and  ic.index_id=ind.index_id
     and  ind. name  like  'PK_%'
     where  ic.object_id=obj.object_id
     and  ic.column_id=col.column_id
)  as  IsPrimaryKey
from  sys.objects obj
inner  join  sys.columns col
on  obj.object_id=col.object_id
left  join  sys.types t
on  t.user_type_id=col.user_type_id
left  join  sys.extended_properties ep
on  ep.major_id=obj.object_id
and  ep.minor_id=col.column_id
and  ep. name = 'MS_Description'
where  obj. name ='[你的表名]';

参考这里:SqlServer 之快速查看表结构 (表描述及字段说明).
查看SQL Server的表字段类型、长度、描述以及是否可为null.

相关推荐
施嘉伟26 分钟前
Oracle 11g RAC ASM磁盘组剔盘、加盘实施过程
数据库·oracle
橘猫云计算机设计2 小时前
springboot基于hadoop的酷狗音乐爬虫大数据分析可视化系统(源码+lw+部署文档+讲解),源码可白嫖!
数据库·hadoop·spring boot·爬虫·python·数据分析·毕业设计
卓怡学长2 小时前
w304基于HTML5的民谣网站的设计与实现
java·前端·数据库·spring boot·spring·html5
冰^3 小时前
MySQL VS SQL Server:优缺点全解析
数据库·数据仓库·redis·sql·mysql·json·数据库开发
电商数据girl3 小时前
产品经理对于电商接口的梳理||电商接口文档梳理与接入
大数据·数据库·python·自动化·产品经理
Spring小子4 小时前
黑马点评商户查询缓存--缓存更新策略
java·数据库·redis·后端
溜溜刘@♞5 小时前
数据库之mysql优化
数据库·mysql
uwvwko6 小时前
ctfhow——web入门214~218(时间盲注开始)
前端·数据库·mysql·ctf
柯3496 小时前
Redis的过期删除策略和内存淘汰策略
数据库·redis·lfu·lru
Tiger_shl6 小时前
【Python语言基础】24、并发编程
java·数据库·python