Search code examples
mysqlphpmyadminlimitrows

Limit the max number of rows in column MySQL


I have searched for a while now how to limit the number max number of rows in a table

I have made a registration system in phpmyadmin and when I come up to 60 users then no one can register anymore.

Hope this information helps, and I hope that you can help me!

I use phpmyadmin.

Here is a picture of what I want to limit to max 60 users to make it more clearer:

enter image description here


Solution

  • CREATE TRIGGER check_user_number 
    BEFORE INSERT ON users FOR EACH ROW
     BEGIN
          IF (SELECT COUNT(*) FROM users) >= 60
          THEN
               CALL 'Cannot add row, the number of users is limited to 60!';
          END IF;
     END;