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.

相关推荐
野犬寒鸦14 分钟前
从零起步学习并发编程 || 第五章:悲观锁与乐观锁的思想与实现及实战应用与问题
java·服务器·数据库·学习·语言模型
VX:Fegn089518 分钟前
计算机毕业设计|基于springboot + vue云租车平台系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
Elastic 中国社区官方博客28 分钟前
跳过 MLOps:通过 Cloud Connect 使用 EIS 为自管理 Elasticsearch 提供托管云推理
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
dishugj29 分钟前
【oracle】RAC开启归档步骤
数据库
IndulgeCui32 分钟前
KingbaseES 数据库与用户默认表空间深度解析与实战分享
数据库
萧曵 丶37 分钟前
MongoDB 核心原理 + 高频面试题
数据库·mongodb
darling3311 小时前
mysql 自动备份以及远程传输脚本,异地备份
android·数据库·mysql·adb
Bruk.Liu1 小时前
(LangChain实战12):LangChain中的新型Chain之create_sql_query_chain
数据库·人工智能·sql·langchain
世界尽头与你1 小时前
MySQL InnoDB的 MVCC 实现机制
数据库·mysql
你刷碗1 小时前
基于S32K144 CESc生成随机数
android·java·数据库