Navicat Blog

Jul 24, 2018 by Robert Gravelle

A database event is a task that runs according to a schedule. Also known as "scheduled events", an event is similar to a cron job in UNIX or a task scheduler task in Windows, except that scheduled events are configured using a database's syntax and/or command-line-interface (CLI). Database events have many uses, such as optimizing database tables, cleaning up logs, archiving data, or generating complex reports during off-peak time.

In previous blogs on this topic, we learned how to configure events using MySQL as our database. Today, we're going to schedule a database task using the Navicat Premium GUI Database Management Tool.

The Navicat Event Designer

In Navicat database management offerings, including Navicat Premium, the Event Designer is the tool for working with events. It's accessible by clicking on the Event button on the main toolbar:

Clicking the Event button opens the Event object list in the Object pane. The Object pane toolbar contains three buttons: Design Event, New Event, and Delete Event. If you have no events defined, only the New Event button will be enabled.

Creating a New Event

Click the New Event button to open a new untitled Definition tab:

You can enter any valid SQL procedure statement in the Definition tab. This can be a simple statement such as "INSERT INTO tbl_users (first_name,last_name) VALUES('Bob','Jones');", or it can be a compound statement written within BEGIN and END statement delimiters. Compound statements can contain declarations, loops, and other control structure statements.

Note that we don't have to write the CREATE EVENT code, as this is handled by Navicat (as we'll see in the following sections).

Here is an event definition that inserts a new row in the sakila.actor table:

Scheduling your Event

Navicat alleviates much of the burden of scheduling events by providing a form for entering scheduling details. The scheduling form is located on the Schedule tab. It supports the adding of Intervals that may comprise either simple or complex time units. Here's a simple example that sets the event to execute 5 minutes after creation:

Here's a more complex event schedule that starts in 5 minutes, and runs every five-and-a-half hours for 3 days:

Saving an Event

To save an Event, click the Save button on the Even tab. If you like, you can preview the generated SQL on the SQL Preview tab before saving it:

Note that the statement is read-only and cannot be edited in the preview.

Adding Comments

You can include comments with your Event on the Comment tab.

It adds them to the CREATE EVENT statement via the COMMENT clause:

Deleting an Event

To delete an Event, select it in the Object tab and click the Delete Event button. A warning dialog will ask you to confirm that you wish to delete the Event:

Modifying an Event

To modify an Event, select it in the Object tab and click the Design Event button. That will open it in the Event tab.

Navicat Blogs
Feed Entries
Blog Archives
Share