Search code examples
mysqlsyntaxsyntax-errormysql-error-1064

MySQL syntax error, can't figure out what's wrong


Hello and thanks for reading my question! I am receiving a syntax error with this code but I cannot figure out what's wrong. Any insight is greatly appreciated.

mysql> create table match (
-> event_id int not null,
-> player1_id int,
-> player2_id int,
-> player1_score int,
-> player2_score int,
-> winner_id int,
-> foreign key (event_id) references event(id)
-> );
ERROR 1064 (42000): 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 (
event_id int not null,
player1_id int,
player2_id int,
player1_score int' at line 1

I can't find any missing commas, and the event table definitely exists with an id column. Any ideas what I'm missing? Thank you!


Solution

  • Match is a reserved word. Enclose it in backticks:

    create table `match` ...