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

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.051e.com
本文地址:http://www.051e.com/it/280608.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号