Wednesday, January 29, 2014

How to list all the table names in the database with sql?

Oracle:


  1. To get all the tables that you own: select * from user_tables;
  2. To get all the tables that you have access: select * from all_tables; 
  3. If you have access to the DBA_TABLES data dictionary view: select * from dba_tables;
  4. From legacy CAT view: select * from CAT where TABLE_TYPE = 'TABLE';
  5. To get all the table columns: select * from all_tab_columns order by owner, table_name, column_id;

DB2:


  1. SELECT * FROM SYSCAT.TABLES
  2. To get all the table columns: SELECT COLNAME FROM SYSCAT.COLUMNS order by TABNAME;



MySQL


  1. SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ;
  2. To list all the table columns: SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS order by TABLE_NAME
-------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.


5 comments:

  1. do you know the query to select tables with a common string in its name ? please write a post on that

    ReplyDelete
    Replies
    1. You can add a WHERE clause to the end of the queries listed in this blog. An example for the Oracle database is, select * from all_tables WHERE TABLE_NAME like '%your string%';

      Delete
    2. Here is the link of the post.

      http://www.flyingjxswithjava.blogspot.com/2014/02/how-to-list-all-table-names-containing.html

      Delete
  2. Thanks for the quick reply. Your posts have very simple explanations, just what i need.
    I am trying to comment using an AOL id, but it doesn't seem to work anyway thanks.

    Selena

    ReplyDelete