tags:

views:

162

answers:

4
CREATE TABLE findings (
  ident VARCHAR(28), 
  code VARCHAR(8), 
  when DATETIME, 
  ip VARCHAR(15)
);
+6  A: 

The word when.

In some databases this is a keyword. So, while processing your create table instruction you may get some errors from your database management system.

Kico Lobo
+9  A: 

when is a keyword in mysql and needs to be quoted with backticks:

CREATE TABLE `findings` (
    `ident` VARCHAR(28),
    `code` VARCHAR(8),
    `when` DATETIME,
    `ip` VARCHAR(15)
);

EDIT: It has been pointed out correctly in the comments, that this is not a good solution. You might be better off finding another name for your column.

soulmerge
A better solution should be to never use the when word, even if quoted.
Kico Lobo
+1 but escaping keywords could be more trouble than it's worth.
Dana the Sane
There's nothing wrong with quoting identifiers in general. The only practical problem is that for MySQL you have to use the backquote character for it, whereas the proper ANSI SQL method is to use double-quotes like `"when" DATETIME`. MySQL can be configured to conform to the standard, but by default it doesn't.
bobince
I picked a new name 'whence'
Nathan
+1  A: 

if you are so keen on using when just prefix the column name with _.

Kalpak
Are you sure this is not DBMS specific?
eyazici
I am sure it works in mysql 5.x. You can select, insert, delete, update etc using the _when field name.
Kalpak
+1  A: 

BTW, is not a good idea to use reserved names for rows names, tables, etc.

mRt