栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Sqlite3 及Postgresql数据库对表及字段信息的查询

Sqlite3 及Postgresql数据库对表及字段信息的查询

Sqlite3查询数据库的总表数:

select name from sqlite_master where type='table' order by name

获取某张表的所有字段信息:

PRAGMA table_info("TableName")

TableName为待查询表名

查询一张表有多少条数据

select count(*) from TableName 

Postgresql对数据表查询指令:

查询指定表的字段名及类型:

select
a.attname as fieldName,
concat_ws('',t.typname,SUBSTRINg(format_type(a.atttypid,a.atttypmod) from '(.*)')) as fieldType
from pg_class c, pg_attribute a , pg_type t
where  c.relname = 'TableName'
and a.attnum>0 
and a.attrelid = c.oid 
and a.atttypid = t.oid 
ORDER BY c.relname DESC,a.attnum ASC

结果只保留两列,列名分别为fieldName, fieldType

TableName为待查询的表名

最近工作用到,记录下来以备后续方便查找。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/280608.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号