How to Change the Comment on a Scheduled Event in MySQL

Suppose you have an existing MySQL event that has a comment. But the comment isn’t as helpful as you’d like it to be, and so you’d like to change it to something else.

This can be done easily with the ALTER EVENT statement along with the COMMENT clause. When we include the COMMENT clause in the ALTER EVENT statement, it replaces whatever comment was in the event with the new comment. If the event didn’t have a comment, then a new comment appears.

Continue reading

Add a Composite Primary Key to an Existing Table in MySQL

In MySQL, adding a composite primary key to an existing table is similar to adding a singular primary key. We define the primary key with the ALTER TABLE statement.

However, when adding a composite primary key we need to use the ADD PRIMARY KEY clause. We can’t define it at the column level. With singular primary keys on the other hand, we have the choice of using the ADD PRIMARY KEY clause or applying it at the column level.

Continue reading

How Scheduled Events Deal with sql_mode in MySQL

When we create a scheduled event in MySQL, the current sql_mode is stored with the event. That causes the event to use the sql_mode that was in effect at the time the event was created. Same with altering an event.

Therefore, if we change the sql_mode after the event was created or altered, it won’t have any impact on the event. In other words, we can safely change our system’s sql_mode without worrying about whether it’s going to mess up any existing scheduled events.

Continue reading

3 Ways to Check the Event Scheduler Status in MySQL

In MySQL we can create events that run on a specified schedule. But events will only run if the Event Scheduler is on. If the Event Scheduler is off or disabled, then such events won’t run as scheduled.

Therefore if we create any events on the server, it’s a good idea to check whether the Event Scheduler is on or not.

Here are three options for doing this using SQL.

Continue reading

Disable Quotes from Table and Column Names When Using SHOW CREATE TABLE in MySQL

If you’re using MySQL’s SHOW CREATE TABLE statement, but you don’t want quotes to be included in the output, this is easily addressed.

By default, SHOW CREATE TABLE (and SHOW CREATE DATABASE) includes quotes around table and column names, etc. When I say “by default”, I mean assuming you haven’t yet changed anything to disable these quotes.

Fortunately there’s an easy way to disable these quotes. MySQL provides us with the sql_quote_show_create system variable. This variable can be set to 1 or 0, which enables and disables such quotes respectively.

Continue reading