Create a unique key column:
CREATE TABLE X
(
ID INTEGER PRIMARY KEY AUTOINCREASE NOT NULL,
A INTEGER,
B INTEGER,
UNIQUE KEY(A, B)
);
INSERT INTO X(A, B) VALUES(1, 2);
INSERT INTO X(A, B) VALUES(2, 2);
INSERT INTO X(A, B) VALUES(1, 3);
INSERT INTO X(A, B) VALUES(2, 3);
INSERT INTO X(A, B) VALUES(1, 2);
The last row will not work, because a combination of a = 1 and b = 2 already exists in the table.
source
share