… for strings, it’s easy… LENGTH(attribute), but for ints, LENGTH always returns “4” for ints, “8” for bigints, etc etc.
So given a statement like this:
create table EMPLOYEE (employeeno bigint NOT NULL PRIMARY KEY);
How could I add a CHECK clause that’ll check to see whether an inserted employeeno is exactly 6 digits?
Use a check constraint to check for
val >= 100000andval <= 999999.If you need to, you can change this to
val >= 0andval <= 999999. Note thatinttypes do not contain any information about leading zeroes, so that information is already lost by the time it hits the database.