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.

相关推荐
svygh12312 分钟前
数据库性能优化系统设计
数据库·性能优化·软件设计·系统设计·设计文档
wilsonzane1 小时前
Mongodb性能优化方法
数据库·mongodb
InterestingFigure1 小时前
Java 使用sql查询mongodb
java·开发语言·数据库·sql·mongodb
吹吹晚风-1 小时前
深入Django(三)
数据库·django·sqlite
xyh20041 小时前
python 10个自动化脚本
数据库·python·自动化
W Y1 小时前
【架构-20】死锁
java·数据库·架构··死锁·银行家算法
just-julie1 小时前
Redis 分布式集群方案 Cluster
数据库·redis·分布式
泡芙冰淇淋ya1 小时前
【redis】redis知识点学习目录整理及简介
数据库·redis·学习
zengson_g1 小时前
如何处理 PostgreSQL 中由于表锁定导致的并发访问问题?
数据库·postgresql
啊取名真困难2 小时前
WhatsApp机器人:提升客户服务效率的自动化工具
数据库·机器人·自动化