CREATE TABLE findings (
ident VARCHAR(28),
code VARCHAR(8),
when DATETIME,
ip VARCHAR(15)
);
views:
162answers:
4
+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
2009-11-30 17:34:37
+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
2009-11-30 17:34:42
A better solution should be to never use the when word, even if quoted.
Kico Lobo
2009-11-30 17:35:57
+1 but escaping keywords could be more trouble than it's worth.
Dana the Sane
2009-11-30 17:36:33
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
2009-11-30 18:11:40
I picked a new name 'whence'
Nathan
2010-04-09 05:54:51
+1
A:
if you are so keen on using when just prefix the column name with _.
Kalpak
2009-11-30 17:41:39
+1
A:
BTW, is not a good idea to use reserved names for rows names, tables, etc.
mRt
2009-11-30 18:25:51