Page 1 of 1

table creation issue

Posted: Tue Dec 30, 2003 9:59 pm
by m3rajk
not sure why but it keeps telling me i have an error at "when...."

i can't find anything that tells me when is a reserved word so i don't really know what's the issue here. any help would be appreciated.

Code: Select all

CREATE TABLE apphist(
       appindex int unsigned NOT NULL auto_increment PRIMARY KEY,
       approver varchar(15) NOT NULL,
       member varchar(15) NOT NULL,
       item tinyint(1) NOT NULL,
       reason tinytext,
       ok tinyint(1) NOT NULL,
       when datetime default '0000-00-00 00:00:00' NOT NULL,
       KEY approver (approver),
       KEY member (member),
       KEY item (item),
       KEY ok (ok),
       KEY when (when)
) TYPE=MyISAM;
note: this table is used to log the approval/rejection of things on the site... incase someone witht he power to approve/reject decides to abuse it. if someone feels it's being abused the ways built in to track down the pattern are by approver, member, item, and date. if it's been approved (ok) is there incase an admin wants to review recent actions of just approvals or rejections.

Posted: Tue Dec 30, 2003 10:19 pm
by microthick
WHEN is a reserved word.

http://www.mysql.com/doc/en/Reserved_words.html

You can either add single quotes around WHEN so that MySQL knows to ignore it, or use another word.

Posted: Wed Dec 31, 2003 8:12 pm
by fractalvibes
Best to give it another name - ApproveDate - JoinDate, whatever to keep yourself and other developers out of trouble. Also best to give columns meaningfull names that are somewhat intuitive so when you or someone else has to maintain this 6 months from now, they will know what the hell 'when' means...

fv

Posted: Wed Dec 31, 2003 8:18 pm
by m3rajk
this is a personal project, so i don't have to worry about other maintainers... but when is when it was approved or rejected (ok would be like ok? since it's being used as a binary ;)) so appdate would probalby be the best thing to change it to