Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 6th, 2008, 10:39 AM
Member
 
Join Date: Mar 2007
Posts: 116
Default 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
Reply
  #2  
Old September 8th, 2008, 01:37 PM
Administrator
 
Join Date: Sep 2006
Posts: 11,312
Default

Check the refmanual for the create table syntax and read about the IF NOT EXISTS clause.
Reply
  #3  
Old September 8th, 2008, 01:44 PM
Member
 
Join Date: Mar 2007
Posts: 116
Default

tnx,

but this one will gove more easiest way (i hope)...
Expand|Select|Wrap|Line Numbers
  1. if(!(mysql_query("select * from table")))
  2. {
  3. echo "table not found";
  4. }
  5. else
  6. {
  7. echo "table found";
  8. }
  9.  

Last edited by Atli; September 8th, 2008 at 10:01 PM. Reason: Added [code] tags.
Reply
  #4  
Old September 8th, 2008, 10:05 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 2,777
Default

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:
Expand|Select|Wrap|Line Numbers
  1. SHOW TABLES LIKE 'myTableName';
  2.  
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
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles