1

I am writing an SQL query for creating a new column in a table. Part of my query includes this:

`phone` INT(8) UNSIGNED NOT NULL DEFAULT 0

The phone must have exactly 8 digits because that is how phone number works for the countries that I am working with. But I am not sure if I need to use INT(8) or only INT. The other way to write that portion would be:

`phone` INT UNSIGNED NOT NULL DEFAULT 0

I know for VARCHAR for example, you specify the length. For example: VARCHAR(50). But in the case of INT I am not sure, since in MySQL, it is already known that INT can store a maximum value of 4294967295 when it is unsigned, so using INT(8) may not make sense because INT will always be INT and by definition, able to store a maximum value of 4294967295 when using UNSIGNED (https://dev.mysql.com/doc/refman/8.0/en/integer-types.html). Thank you.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
  • 1
    It's fantastically unlikely that something called 'phone' would be an integer. You rarely need to add up phone numbers, and 01234 and 1234 are NOT the same phone number! – Strawberry Jan 24 '19 at 23:52
  • 1
    `+44 303 123 7300` is a phone number, as is `(555)555-5555x2202` and so is `1-800-ODD-BIRD`. They are not just "numbers". – tadman Jan 25 '19 at 01:43

1 Answers1

2

INT(8) is an obsolete formatting construct. Its best to ignore those on int types.

VARCHAR is probably better for PHONE types that don't have numberic operations done on them.

danblack
  • 12,130
  • 2
  • 22
  • 41
  • Thank you, you are right. I found the same advice at https://stackoverflow.com/questions/24353778/which-is-best-data-type-for-phone-number-in-mysql-and-what-should-java-type-mapp. – Jaime Montoya Jan 24 '19 at 23:47