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.
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,
CHECK (playerid1 <> playerid2));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With