Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-19
4
Medium Priority
?
359 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 2000 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 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

916 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