I have two SQL statements:

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);

I am 99% sure I should be able to condense them into one, i.e:

CREATE TABLE table(...
                   playerid2 INT NOT NULL REFERENCES players(playerid) CHECK(playerid1 <> playerid2),
                   ...);

However, I am consistently getting a syntax error. AFAIK, this is where the constraint should be.

Edit
Report