views:

100

answers:

3

I can't figure out what's causing my INSERT INTO's to fail to certain table in MySql. I can manage them to other tables. The table looks like:

CREATE TABLE IF NOT EXISTS `Match` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `match_no` int(11) NOT NULL,
  `season` int(11) NOT NULL,
  `hometeam` int(11) NOT NULL,
  `awayteam` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `match_no` (`match_no`),
  KEY `season` (`season`),
  KEY `hometeam` (`hometeam`),
  KEY `awayteam` (`awayteam`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

And the command is

INSERT INTO Match (`match_no`, `season`, `hometeam`, `awaytem`) VALUES (1, 1, 2, 3)

All I get is:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Match (match_no, season, hometeam, awaytem) VALUES (1, 1, 2, 3)' at line 1

I have checked the manual and half-a-dozen examples from the web and whatnought and tried all sorts of changes to the syntax in case there is some MySql specific oddity, but nothing seems to work.

+4  A: 

Match is a reserved word in MySQL.

Here goes the list of MySQL reserved words

Enclose Match in back ticks as:

INSERT INTO `Match` .........

Also as Pax pointed out you've misspelt a column name.

codaddict
Think you mean "reserved" word :)
AvatarKava
Oops :D thanx for pointing :)
codaddict
+5  A: 

Change awaytem to awayteam and see how it goes and use `Match` as the table: match is a reserved word.

paxdiablo
Ah, the awaytem was just a typo I did when I quickly wrote the example, but the other hint was the key! So thank's a lot, can't believe how much time I wasted on this...
Makis
As a side note: While you *can* use a reserved word as a table/column name in MySQL (and other DMBS), I'd strongly recommend against it. It will be a source of trouble in the future, and not all tools may support the necessary tricks (such as using quotes). Just use a different table name, if you can.
sleske
Yeah, I don't usually use them, but this is just a small app that once I get ready will probably never touch again.
Makis
+2  A: 

Match is a reversed word
so,

INSERT INTO `Match`

note the same backticks you used for the fieldnames
these are not for decoration

Col. Shrapnel