CREATE TRIGGER exh_locs_check
BEFORE INSERT on exhibits
FOR EACH ROW
BEGIN
DECLARE @exhibit_placements int;
SET @exhibit_placements = (SELECT COUNT(*) FROM exhibits
JOIN collections_locations
ON exhibits.id_коллекции = collections_locations.id_коллекции
WHERE exhibits.id = new.id
GROUP BY exhibits.id);
IF (@exhibit_placements) = 0 THEN
SIGNAL SQLSTATE '12345' SET MESSAGE_TEXT='Error';
END IF;
END