查询数据库内表的字段及注释

内容:

获取数据库表字段、字段类型、字段注释等。现已汇总数据库:SqlServer、MySql、Oracle


SqlServer数据库

TableName:表名;
ColumnName:字段名;
ColumnType:字段类型;
IsNullable:是否能为空;
DefaultData:默认值;
ColumnDescription:字段注释;

查询某数据库某张表的字段与注释

use 数据库名
select a.name  TableName,b.name  ColumnName,data_type ColumnType,s.IS_NULLABLE IsNullable,s.COLUMN_DEFAULT DefaultData,C.value  ColumnDescription
from sys.tables a 
inner join sys.columns b on b.object_id = a.object_id
left join information_schema.columns s on s.TABLE_NAME = a.name and s.COLUMN_NAME = b.name
left join sys.extended_properties c on c.major_id = b.object_id and c.minor_id = b.column_id
where a.name ='表名'
Order by a.name,s.ORDINAL_POSITION;

go

在这里插入图片描述

查询某数据库所有表的字段与注释

use 数据库名
select a.name  TableName,b.name  ColumnName,data_type ColumnType,s.IS_NULLABLE IsNullable,s.COLUMN_DEFAULT DefaultData,C.value  ColumnDescription
from sys.tables a 
inner join sys.columns b on b.object_id = a.object_id
left join information_schema.columns s on s.TABLE_NAME = a.name and s.COLUMN_NAME = b.name
left join sys.extended_properties c on c.major_id = b.object_id and c.minor_id = b.column_id
where a.name in (select name from sys.tables)
Order by a.name,s.ORDINAL_POSITION;

go

在这里插入图片描述


MySql数据库

DatabaseName:数据库名;
TableName:表名;
ColumnName:字段名;
ColumnType:字段类型;
IsNullable:是否能为空;
DefaultData:默认值;
ColumnDescription:字段注释;

查询某数据库某张表的字段与注释

select a.TABLE_SCHEMA DatabaseName,a.TABLE_NAME TableName,a.COLUMN_NAME ColumnName,a.COLUMN_TYPE ColumnType,a.IS_NULLABLE IsNullable,a.COLUMN_DEFAULT DefaultData,a.COLUMN_COMMENT ColumnDescription
from COLUMNS a
WHERE TABLE_SCHEMA = '数据库名' and TABLE_NAME = '表名'
ORDER BY TABLE_SCHEMA,TABLE_NAME,ORDINAL_POSITION;

在这里插入图片描述

查询某数据库所有表的字段与注释

select a.TABLE_SCHEMA DatabaseName,a.TABLE_NAME TableName,a.COLUMN_NAME ColumnName,a.COLUMN_TYPE ColumnType,a.IS_NULLABLE IsNullable,a.COLUMN_DEFAULT DefaultData,a.COLUMN_COMMENT ColumnDescription
from COLUMNS a
WHERE TABLE_SCHEMA = '数据库名'
ORDER BY TABLE_SCHEMA,TABLE_NAME,ORDINAL_POSITION;

在这里插入图片描述


Oracle数据库

DatabaseName:数据库名;
TableName:表名;
ColumnName:字段名;
ColumnType:字段类型;
IsNullable:是否能为空;
DefaultData:默认值;
ColumnDescription:字段注释;
注意:user_tab_columns表的字段需要全大写

查询某数据库某张表的字段与注释

select a.TABLE_NAME  TableName,a.COLUMN_NAME ColumnName,a.DATA_TYPE ColumnType,a.NULLABLE IsNullable,
a.DATA_DEFAULT DefaultData,b.comments  ColumnDescription
from user_tab_columns a 
left join user_col_comments b on a.TABLE_NAME = b.table_name and a.COLUMN_NAME = b.column_name
where a.TABLE_NAME = '表名'
Order by a.TABLE_NAME,a.COLUMN_ID;

查询某数据库所有表的字段与注释

select a.TABLE_NAME  TableName,a.COLUMN_NAME ColumnName,a.DATA_TYPE ColumnType,a.NULLABLE IsNullable,
a.DATA_DEFAULT DefaultData,b.comments  ColumnDescription
from user_tab_columns a 
left join user_col_comments b on a.TABLE_NAME = b.table_name and a.COLUMN_NAME = b.column_name
Order by a.TABLE_NAME,a.COLUMN_ID ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开心,你呢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值