表用户和属性已正确创建
CREATE TABLE Properties
(
ID int AUTO_INCREMENT,
language int,
stonecolor int,
gamefield int,
UserID int,
PRIMARY KEY(ID),
FOREIGN KEY(language) REFERENCES Language(ID),
FOREIGN KEY(stonecolor) REFERENCES StoneColor(ID),
FOREIGN KEY(gamefield) REFERENCES GameField(ID)
) ENGINE = INNODB;
CREATE TABLE User
(
ID int AUTO_INCREMENT,
vorname varchar(30) NOT NULL,
name varchar(30) NOT NULL,
email varchar(40) NOT NULL,
password varchar(40) NOT NULL,
nickname varchar(15) NOT NULL,
score int,
isadmin int DEFAULT 0,
gamesPlayed int,
properties int NOT NULL,
PRIMARY KEY(ID),
UNIQUE (email),
UNIQUE (nickname)
) ENGINE = INNODB;
但ALTER TABLE User
不起作用。
ALTER TABLE User
(
ADD CONSTRAINT userPropertie
FOREIGN KEY(properties)
REFERENCES Properties(ID)
)
想不通为什么?
我用这个作为参考http://www.w3schools.com/sql/sql_foreignkey.asp
错误 1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的 '( ADD CONSTRAINT userPropertie FOREIGN KEY(properties) REFERENCES Properties(' 附近使用正确的语法