Wednesday, February 5, 2014

How to list all the table names containing a particular string in a database with sql?

In Oracle database



       1. To get all the tables that you own:

           SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME like '%<your string>%';

       2. To get all the tables that you can access: 

          SELECT unique TABLE_NAME FROM ALL_TABLES WHERE TABLE_NAME like '%<your string>%';

       3. If you have access to the DBA_TABLES view: 

           SELECT unique TABLE_NAME FROM DBA_TABLES WHERE TABLE_NAME like '%<your string>%';

        4. From the legacy CAT view: 

            SELECT TABLE_NAME FROM CAT WHERE TABLE_TYPE='TABLE' and TABLE_NAME like '%<your string>%';

DB2 Database


SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE = 'T' and TABNAME like '%<your string>%';

MySQL Database


SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME like '%<your string>%';

----------------------------------------------------------------------------------------------------------------

                        
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.

2 comments:

  1. Please write about selecting constraints like primary key by name.

    Selena.

    ReplyDelete
    Replies
    1. Selena, please visit the following link. Thank you.
      http://flyingjxswithjava.blogspot.com/2014/02/list-primary-keysforeign-keys-by-table.html

      Delete