我有两个sql语句:
CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,playerid1 INT NOT NULL REFERENCES players(playerid),playerid2 INT NOT NULL REFERENCES players(playerid),added TIMESTAMP AS CURRENT_TIMESTAMP NOT NULL); ALTER TABLE legs ADD CONSTRAINT distinct_players CHECK(playerid1 <> playerid2);
我99%肯定我能把它们凝聚成一个,即:
CREATE TABLE table(... playerid2 INT NOT NULL REFERENCES players(playerid) CHECK(playerid1 <> playerid2),...);
但是,我一直在收到语法错误. AFAIK,这是约束应该在哪里.
解决方法
CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,added TIMESTAMP AS CURRENT_TIMESTAMP NOT NULL,CHECK (playerid1 <> playerid2));