Answer the question
In order to leave comments, you need to log in
How to guarantee the uniqueness of a record using a complex key?
There is such a simple table, with 3 foreign keys. How can I make it impossible to re-create an entry with the same values for these three keys? Create a complex key based on them?
And how to do it in the Workbench environment, just additionally specify each one as a primary key?
Answer the question
In order to leave comments, you need to log in
CREATE TABLE user_roles(
user_id INT NOT NULL,
role_id INT NOT NULL,
PRIMARY KEY(user_id,role_id),
FOREIGN KEY(user_id) REFERENCES users(user_id),
FOREIGN KEY(role_id) REFERENCES roles(role_id)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question