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.

相关推荐
背太阳的牧羊人20 分钟前
Neo4j 的向量搜索(Neo4jVector)和常见的向量数据库(比如 Milvus、Qdrant)之间的区别与联系
数据库·neo4j·milvus
liulun36 分钟前
在浏览器中使用SQLite(官方sqlite3.wasm)
数据库·sqlite·wasm
IT项目管理2 小时前
达梦数据库DMHS介绍及安装部署
linux·数据库
你都会上树?2 小时前
MySQL MVCC 详解
数据库·mysql
大春儿的试验田2 小时前
高并发收藏功能设计:Redis异步同步与定时补偿机制详解
java·数据库·redis·学习·缓存
Ein hübscher Kerl.2 小时前
虚拟机上安装 MariaDB 及依赖包
数据库·mariadb
醇醛酸醚酮酯3 小时前
Qt项目锻炼——TODO清单(二)
开发语言·数据库·qt
GreatSQL社区4 小时前
用systemd管理GreatSQL服务详解
数据库·mysql·greatsql
掘根4 小时前
【MySQL进阶】错误日志,二进制日志,mysql系统库
数据库·mysql
weixin_438335404 小时前
基础知识:mysql-connector-j依赖
数据库·mysql