0

How to write an SQL query which would check the length of an integer field?

I am making a table with a column named Phone number (having INT data type) and I want that this field always checks whether or not the value inserted in it, is of 10 digits. How do I accomplish that? Any help would be appreciated.

6th Feb 2022, 6:24 PM
Optimus Prime
Optimus Prime - avatar
4 Respostas
0
Optimus Prime Use LEN() function. SELECT LEN("Hello"); Output : 5
6th Feb 2022, 6:31 PM
Manimaran K
Manimaran K - avatar
0
This i am asking for SQL sir. Length() is the name of the function in SQL but I am not getting how to get the value checked using the CHECK constraint.
6th Feb 2022, 6:45 PM
Optimus Prime
Optimus Prime - avatar
0
What date-type are you using for the phones number column, I don't want to assume it's a 'text' (or what ever the equivalent is in mysql)?
6th Feb 2022, 8:13 PM
rodwynnejones
rodwynnejones - avatar
0
It is int data type.
7th Feb 2022, 7:21 AM
Optimus Prime
Optimus Prime - avatar