Check if table is exist or not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maheswaran
    New Member
    • Mar 2007
    • 190

    Check if table is exist or not

    May this question exist....But i confused...I want to check whether the table is exist or not ....


    Like i run a project , on that project i create a temp tables while run time.... on that i want to chech a table is exist or not...

    if employee table is exist

    exit;
    else
    create table employee
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Check the refmanual for the create table syntax and read about the IF NOT EXISTS clause.

    Comment

    • maheswaran
      New Member
      • Mar 2007
      • 190

      #3
      tnx,

      but this one will gove more easiest way (i hope)...
      [code=php]
      if(!(mysql_quer y("select * from table")))
      {
      echo "table not found";
      }
      else
      {
      echo "table found";
      }
      [/code]
      Last edited by Atli; Sep 8 '08, 09:01 PM. Reason: Added [code] tags.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        That is an extremely wasteful method. You would in fact be fetching ALL the data from that table, just to see if it exists.

        A far better way would be to use the SHOW TABLES command, like:
        [code=mysql]
        SHOW TABLES LIKE 'myTableName';
        [/code]
        Which would return an empty set if the table doesn't exists, or a single row if it does.

        P.S.
        Use [code] tags when posting code examples.
        Please read the Posting Guidelines before posting.

        Thank you.
        MODERATOR

        Comment

        Working...