I'm using mysql (mariadb). I have one table "events_ratings", which contains 4 columns
CREATE TABLE `event_ratings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_event` int(11) NOT NULL,
`rating` int(1) NOT NULL,
`id_user` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
PRIMARY KEY `id`,
ADD CONSTRAINT `idevent` FOREIGN KEY (`id_event`) REFERENCES `events_fb` (`id`) ON UPDATE CASCADE,
ADD CONSTRAINT `iduser` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
The aim of this table is to provide user rating, so :
- Each user can rate an event (based on his unique "id_user"). The user could rates many events as he wants but never the same one.
So basically id_user AND id_event should never have duplicated values. I know how to make a column unique but how to make a constraint based on two fields ?
thanks