2

I have an SQL script which creates a scheduled event:

CREATE EVENT "Daily_1200PM"
SCHEDULE "Daily_1200PM" START TIME '12:00' EVERY 24 HOURS
HANDLER
begin 
   -- Blah blah, do some stuff here
end;

I would like to remove this event, if it exists. I know I can remove the event with the following:

DROP EVENT "Daily_1200PM"

But for some databases, the the event doesn't actually exist, so an error is thrown.

How do I delete the event only if it exists?

JamesPD
  • 620
  • 2
  • 8
  • 22

1 Answers1

5
if exists( select * from sys.sysevent where event_name='Daily_1200PM' ) then
    drop event Daily_1200PM;
end if
Graeme Perrow
  • 56,086
  • 21
  • 82
  • 121