I use the following sql statement in mysql:
CREATE TABLE "User"(
userId int NOT NULL AUTO_INCREMENT,
userRoleId int NOT NULL,
taalId int NOT NULL,
hotelId int NOT NULL,
gebruikersnaam varchar(40) NOT NULL,
wachtwoord varchar(40) NOT NULL,
email varchar(50) NOT NULL,
FOREIGN KEY (userRoleId) REFERENCES UserRole (userRoleId),
FOREIGN KEY (taalId) REFERENCES Taal (taalId),
FOREIGN KEY (hotelId) REFERENCES Hotel (hotelId),
PRIMARY KEY(userId)
);
But i get the follwoing Mysql 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 '"User"( userId int NOT NULL AUTO_INCREMENT, userRoleId int NOT NULL, taalI' at line 1
What is going wrong?
Edit: the tables UserRole, Taal and Hotel are created properly without a problem.
To escape a reserved word, use backticks not quotes:
CREATE TABLE `User` -- <== Notice backticks instead of quotes
(
userId int NOT NULL AUTO_INCREMENT,
userRoleId int NOT NULL,
taalId int NOT NULL,
hotelId int NOT NULL,
gebruikersnaam varchar(40) NOT NULL,
wachtwoord varchar(40) NOT NULL,
email varchar(50) NOT NULL,
FOREIGN KEY (userRoleId) REFERENCES UserRole (userRoleId),
FOREIGN KEY (taalId) REFERENCES Taal (taalId),
FOREIGN KEY (hotelId) REFERENCES Hotel (hotelId),
PRIMARY KEY(userId)
);