I am trying to create a table that references another table in my db however I am receiving this error.
#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 'UInt32 PRIMARY KEY, name VARCHAR(20), handle VARCHAR(20), countryName VARCHAR(20' at line 1
I have had a look at error #1064 on the mySQL refrence page but its abit of a vuage error just giving the outline of its structure.
Error: 1064 SQLSTATE: 42000 (ER_PARSE_ERROR)
Message: %s near '%s' at line %d
this is the code I have tried to execute
CREATE TABLE User (userID UInt32 PRIMARY KEY, name VARCHAR(20), handle VARCHAR(20), countryName VARCHAR(20) references Countries(SID))engine=innodb;
Countries table has already been created, so I am not entirely sure what is causing the problem
any help would be greatly appreciated.
added not this is how I have defined countries
CREATE TABLE Countries (countryName VARCHAR(20) PRIMARY KEY)engine=innodb;
UPDATED response:
Moving the constraint definition out of the table definition helped isolate the problem:
Table creation failure was caused by the use of the
UInt32data type. Changed toint, table creation succeeded.Foreign key constraint was referring to the wrong column in
Countries. It was referring toSIDbut needed to refer tocountryName.