Solved

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

Posted on 2011-09-19
4
346 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Creating and Managing Databases with phpMyAdmin in cPanel.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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