MySQL – Best Datatype for Numbers with Hyphens

MySQLmysql-workbench

I know it might sound silly, I have to look up MySQL manual reference and another MySQL forum. as I could not find what is right datatype for numbers with '-' e.g

'405-6444235-1711500'

I'm not sure this number datatype like TINYINT, SMALLINT, MEDIUMINT INT and BIGINT will not working on this.
I'm not sure if varchar is a right choice for this.

So Any Suggest what is the right choice for this before I build a new table and Data await to upload it.

Best Answer

With hyphens, it's a string, full stop!

You could store it as a BIGINT (without the hyphens) and format it using the hyphens on the client side - putting hyphens at 4 and 12.

However, if the position of the hyphens varies, you'll have to store it as a string and not any form of number.

You should only store values as numbers if you're going to add/subtract/multiply or divide them - otherwise, they are strings and not "numbers" anyway! How do you perform mathematical operations with "numbers" which have hyphens?