String Length Constraints

Let’s learn about string length constraints.

We'll cover the following

The length of a string value for a property—such as the title of a book—may have to be constrained, typically by a maximum length, but also by a minimum length. In an SQL table definition, a maximum string length can be specified in parenthesis appended to the SQL datatype CHAR or VARCHAR, as in VARCHAR(50).

String length constraints in UML

UML does not define any special way of expressing string length constraints in class diagrams. Of course, we always have the option to use an invariant for expressing any kind of constraint, but it seems preferable to use a simpler form of expressing these property constraints. One option is to append a maximum length, or both a minimum and a maximum length, in parenthesis to the datatype name, as in the table below:

Get hands-on with 1200+ tech skills courses.