19
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
(
ADD CONSTRAINT userPropertie
FOREIGN KEY(properties)
REFERENCES Properties(ID)
)
表已正確創建,但ALTER TABLE不起作用。不知道爲什麼?ALTER TABLE add constraint
我用這個作爲參考http://www.w3schools.com/sql/sql_foreignkey.asp
錯誤1064 - 你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的正確語法手冊「( ADD CONSTRAINT userPropertie 外鍵(屬性) 參考屬性(」第2行
哦,夥計,謝謝! – ABLX 2012-04-17 14:33:58