0

Am using the below code to create an EVENT in MYSQL. In this time i want to drop and create a table using a query.

Drop  Event  if exists EVT_UP_TIMESHEET;
CREATE EVENT EVT_UP_TIMESHEET
  ON SCHEDULE EVERY '1' Day
  STARTS '2012-08-01 12:00:00'
DO

  Drop table if exists tbl_temp;

 create table tbl_temp as ( SELECT e.userid            AS Employee_ID,

       e.memo              AS Employee_Name,
   e.Department        AS Department,
.....

It returns the following error:

ERROR : Table tbl_temp already exists.

Please help me to do this.

2
  • Try to call just DROP TABLE .. and look if it will be dropped. Commented Aug 31, 2012 at 6:43
  • yes when i execute the drop comment the table dropped successfully. Commented Aug 31, 2012 at 6:49

2 Answers 2

1

Use CREATE TABLE IF NOT EXISTS tbl_temp instead of create table tbl_temp

Or to delete the table you can use TRUNCATE TABLE instead of DROP TABLE and to create you can use INSERT...SELECT instead of CREATE TABLE.

Sign up to request clarification or add additional context in comments.

1 Comment

I want to drop that table every day and create again.
0

As a workaround - try to use TRUNCATE TABLE and INSERT...SELECT statements instead of DROP/CREATE TABLE.

4 Comments

I have encounter the new error index i_emp_temp is already exists "create index i_emp_tmp on tbl_temp (employee_id,punchdate);"
Create table with all its indexes once. And do not change table structure from the event.
K i accept this. But the table doesn't truncate.Records inserted double time.
Hm, it looks like a MySQL bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.