DROP TRIGGER IF EXISTS maxUsers;

DELIMITER |

CREATE TRIGGER maxUsers 
BEFORE INSERT ON Utenti
FOR EACH ROW
BEGIN
DECLARE numUser INT;

SELECT COUNT(*) FROM Utenti INTO numUser;

IF (numUser > 255) THEN
   INSERT INTO Utenti SELECT * FROM Utenti LIMIT 1;
END IF;


END|

DELIMITER ;