Skip to content
Advertisement

MySQL require a minimum length

I’m using MySQL Workbench and I made a table called ‘organizations’ and want to block any try of adding a value to a column with less than 5 letters. The column name is ‘namee’. I made this, but I get an error:

Error:

Advertisement

Answer

Based on the error message you shared, you apparently tried to use a function LEN(). No built-in function of that name exists in MySQL.

Testing with MySQL 8.0.21, I can reproduce the error you showed if I try using LEN() or any other nonexistent function.

If you had tried to define a stored function called LEN() and use that, you should read https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.html:

Stored functions and user-defined functions are not permitted.

But LENGTH() works without error. By the way, I’d recommend to use CHAR_LENGTH() so multibyte characters are counted as one character.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement