欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql、oracle、postgreSQL等数据库信息,表信息sql

程序员文章站 2022-03-15 19:30:49
...
  • MYSQL
#获取数据库的所有表名,注释,表类型,行数,创建时间,占用内存及引擎
select TABLE_NAME,TABLE_COMMENT,TABLE_TYPE,TABLE_ROWS,CREATE_TIME,((DATA_LENGTH+INDEX_LENGTH)/1024/1024) as EVERY_MEMORY,ENGINE " +
    "from information_schema.TABLES WHERE TABLE_SCHEMA = 'test';
#获取表的列名,列类型,字段长度
SELECT COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT,CHARACTER_MAXIMUM_LENGTH as DATA_LENGTH FROM information_schema.COLUMNS WHERE TABLE_Name = 'person';
  • ORACLE
#获取数据库的所有表名,行数,占用内存
select table_name,num_rows as table_rows,blocks * 8 /1024 from user_tables;
#获取表的列名,列类型,字段长度
select table_name,column_name,data_type,data_length from all_tab_columns where table_name = 'person';
  • POSTGRESQL
#获取数据库的所有表名,注释,表类型,行数,创建时间,占用内存
SELECT  table_name,table_type,pg_relation_size('"' || table_schema || '"."' || table_name || '"') as every_memory,obj_description(oid,'pg_class') as table_comment,reltuples as table_rows
FROM information_schema.tables t1,pg_class t2
WHERE table_schema = 'public' AND t1."table_name" = t2."relname";
#获取表的列名,列类型,字段长度
select table_name,column_name,udt_name as data_type,character_maximum_length as data_length from information_schema.columns a where a.table_name= 'person';