-2

I have a field of phone_numbers, I want to set a limit (minimum/maximum character length of, say,14.) The only thing I can do through ArcGIS pre-existed statements is to set either the minimum or maximum. I specifically want to set the limitation for both minimum and maximum number of characters.

"phone_number" = 14

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • What version of MySQL are you using? 8.0 adds support for `CHECK` constraints. – Barmar Aug 23 '19 at 23:00
  • As far as I know, arcgis pro does not support mysql database connections. Furthermore, no matter what database engine you use, AGP will connect to that directly, so using database features not supported by AGP may result in unexpeted behaviour within AGP. Therefore, I would remove the direct database product tag from the question. – Shadow Aug 24 '19 at 03:18
  • https://www.db-fiddle.com/f/c8pDcfP8maUcmhtKHTRtgf/1 – Strawberry Aug 24 '19 at 07:06

1 Answers1

0

If you're using MySQL 8.0 or higher, you can use a CHECK constraint.

CREATE TABLE phone_numbers (
    user_id INT,
    phone_num CHAR(14) NOT NULL,
    CHECK LENGTH(phone_num) = 14
)

In an earlier version you could use BEFORE INSERT and BEFORE UPDATE triggers to check the length and signal an error. See CHECK constraint in MySQL is not working for examples.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Barmar
  • 741,623
  • 53
  • 500
  • 612