table creation issue

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

table creation issue

Post 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.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post 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.
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
Post Reply