• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

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

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
XenekStoehr
Asked:
XenekStoehr
1 Solution
 
mansooralia_yahooCommented:
check this link: http://dev.mysql.com/doc/refman/5.5/en/drop-table.html it will delete the table if it exists.
0
 
AnuTijiCommented:
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
 
nishant joshiTechnology Development ConsultantCommented:
0
 
XenekStoehrAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now