Which data types should I use?

Asked by At

I am unsure of which data types to use for the following attributes:

  • A phone number (which is made up of 10 numbers)

  • A client name

  • A numeric product ID that acts as a Primary Key

  • The location/state of the client (which only has 1 out of 8 possible values)

Im not sure of whether to use CHAR or VARCHAR for some of these, or if there is another type I should use.

3 Answers

1
Neel Bhanushali On Best Solutions
  1. phone number -> decimal(10, 0)
  2. name -> varchar(length)
  3. productId -> integer unsigned (you can use autoincrement)
  4. location -> enum('possible value 1', 'possible value 2', ...)
4
Nit On
  1. INTEGER (Always used for numeric numbers) (If you are allowing "+" & etc. use VARCHAR)
  2. CHAR (for characters)
  3. INTEGER (as mentioned above)
  4. VARCHAR (It accepts both the character and the number)

Note: You should use "varchar" for all you needs.

1
Suhail Mushtaq On

Understanding the difference between Char, Varchar will help you out.

  • Char is fixed length.
  • Varchar is variable-length. So in case, you have some fixed length variables like Gender, you can go with char, If you have some variable length variable like Name in your case, you can go with Varchar.