show all tables in DB2 using the LIST command

后端 未结 6 650
天涯浪人
天涯浪人 2021-01-31 09:26

This is embarrassing, but I can\'t seem to find a way to list the names of the tables in our DB2 database. Here is what I tried:

root@VO11555:~# su - db2inst1
ro         


        
相关标签:
6条回答
  • 2021-01-31 10:04

    I'm using db2 7.1 and SQuirrel. This is the only query that worked for me.

    select * from SYSIBM.tables where table_schema = 'my_schema' and table_type = 'BASE TABLE';
    
    0 讨论(0)
  • 2021-01-31 10:04

    have you installed a user db2inst2, i think, i remember, that db2inst1 is very administrative

    0 讨论(0)
  • 2021-01-31 10:18

    Run this command line on your preferred shell session:

    db2 "select tabname from syscat.tables where owner = 'DB2INST1'"
    

    Maybe you'd like to modify the owner name, and need to check the list of current owners?

    db2 "select distinct owner from syscat.tables"
    
    0 讨论(0)
  • 2021-01-31 10:24

    Connect to the database:

    db2 connect to <database-name>
    

    List all tables:

    db2 list tables for all
    

    To list all tables in selected schema, use:

    db2 list tables for schema <schema-name>
    

    To describe a table, type:

    db2 describe table <table-schema.table-name>
    

    credit http://onewebsql.com/blog/list-all-tables

    0 讨论(0)
  • 2021-01-31 10:27
    select * from syscat.tables where type = 'T'
    

    you may want to restrict the query to your tabschema

    0 讨论(0)
  • 2021-01-31 10:28

    To get a list of tables for the current database in DB2 -->

    Connect to the database:

    db2 connect to DATABASENAME user USER using PASSWORD
    

    Run this query:

    db2 LIST TABLES
    

    This is the equivalent of SHOW TABLES in MySQL.

    You may need to execute 'set schema myschema' to the correct schema before you run the list tables command. By default upon login your schema is the same as your username - which often won't contain any tables. You can use 'values current schema' to check what schema you're currently set to.

    0 讨论(0)
提交回复
热议问题