SQL to get table list (Oracle / MySQL / PostgreSQL / SQLite / SQLServer / Cassandra)

Introduction

MiluDB Viewer (GUI DB client using JavaFX) I forgot what I made when I made it, so make a note of it.

This time, it is about SQL to get the table list.

Oracle - 12c Release 2

select object_name, status from all_objects
where
object_type = 'TABLE'
and
owner = 'Schema name'
order by owner, object_name

range of status VALID INVALID

MySQL - 8.0.11/SQLServer - 2017

select  table_name from information_schema.tables 
where 
  table_type='BASE TABLE' 
  and 
  table_schema = 'Schema name'
order by table_name

MySQL and SQL Server can be obtained with the same SQL !!

PostgreSQL - 10.4

select 
  c.relname  
from 
  pg_class c join 
  pg_namespace n on n.oid = c.relnamespace 
where 
  n.nspname = 'Schema name' 
  and 
  c.relkind = 'r' 
order by c.relname

SQLite

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

Cassandra - 3.9.0

select table_name from system_schema.tables
where
  keyspae_name = 'Schema name'
order by table_name

DB other than the above

As I learned later, if JDBC implements it, In the getTables () method of java.sql.DatabaseMeataData, Since java.sql.ResultSet is returned, You can get it with resultset.getString ("TABLE_NAME").

Reference URL https://avaldes.com/jdbc-statement-databasemetadata-gettables-example/

Recommended Posts

SQL to get table list (Oracle / MySQL / PostgreSQL / SQLite / SQLServer / Cassandra)
SQL to get the schema list (Oracle / MySQL / PostgreSQL / SQLServer / Cassandra)
Change from SQLite3 to PostgreSQL
Change DB from SQLite to MySQL
Rails DB PostgreSQL changed to MySQL