Solved

temporary table already exists on second run after query fails on first run

Posted on 2011-09-19
4
334 Views
Last Modified: 2012-05-12
I have a script where I create a temporary table called 'tempticks'.
Occasionally the query fails, and then I get an error when trying to run it later...

table 'tempticks' already exists.

My Question:- Can I do a check for a table prior to creation, or can I 'autodelete' a table (in case it exists) at the start of a mysql query? I really just want my query to be as rock solid as possible.

See my other open questions for the full query, or further details.
0
Comment
Question by:XenekStoehr
4 Comments
 
LVL 2

Accepted Solution

by:
mansooralia_yahoo earned 500 total points
ID: 36559253
check this link: http://dev.mysql.com/doc/refman/5.5/en/drop-table.html it will delete the table if it exists.
0
 
LVL 4

Expert Comment

by:AnuTiji
ID: 36559258
Hi

Please find the below TSQL to check if the temporary table exists

IF object_id('tempdb..#tempticks) IS NOT NULL
BEGIN
   DROP TABLE #tempticks
END
0
 
LVL 14

Expert Comment

by:nishant joshi
ID: 36559272
0
 
LVL 1

Author Closing Comment

by:XenekStoehr
ID: 36596692
Ok, well, that was easy. I must have missed the part of the manual that referred to the "if exists" section.
This is the line I added to achieve a perfectly working solution. I added this line prior to the create table line...

DROP TABLE IF EXISTS tempticks;

Thank you Mansooralia
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now