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.

相关推荐
RestCloud20 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud20 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence1 天前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
DemonAvenger1 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
AAA修煤气灶刘哥2 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud2 天前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术2 天前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug2 天前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom2 天前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*2 天前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud