sqlmysqldatabasespecial-charactersnaming

A column called Status in MySQL


I've been using MySQL and I need a column called “Status” in a table.

I know this word “Status” is a keyword in MySQL, and I would like to know if I will have problems with it if I write SQL statements like:

select t.Id, t.Name, t.Status from Table t

Or in triggers:

Set new.Status = 1;

if (new.Status <> old.Status) then
  /* do something */
end if

Or should I rename it for another word?


Solution

  • Status can be its own column if you wrap it, in MySQL, with ``.

    SELECT `t`.`Status`. FROM `t`
    

    But for the sake of avoiding confusion later on, it may be better for you to distinguish it in some other way.