Forum Moderators: open

Message Too Old, No Replies

Best field type for small numbers

Total mysql noob!

         

madmatt69

7:41 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey all,

Very new to mysql, at least editing it and all that.

I'd like to add a field to an existing database. The field will just contain a series of numbers, no more that 4 numbers per entry. It's basically a list of some telephone area codes.

In phpmyadmin I have several options under the "Type" menu - I'm sure I could just use "varchar" but I'm wondering if there's some sort of more efficient type I should be using or anything like that, since this DB will grow to be pretty big.

Thanks for any info, and patience as I stumble through this :)

coopster

8:28 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You mean you are going to store the numbers as follows?
myField: 
--------
123,456,789,012
987,654,321,098

In a string or something like that? Why not separate them into rows rather than all in one column? It is going to make searching by area code much, much easier and much faster.

madmatt69

8:30 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it would be rows.

For example I have a db called 'country' and that includes a list of some countries in each row.

So:
Germany
---
France
---
USA

etc. so for Germany i'd like add "Country_code" and put the number in there.

Know what I mean?

coopster

8:34 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I believe so. Then I would create the table with a code column that would contain one code per entry. If you need more than one entry per country you can do so.
Turkey 123 
France 456
Canada 789
Canada 012

To hold an integer that size I would use SMALLINT.

madmatt69

8:45 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool, thanks for the advice - I'll give it a shot!

coopster

9:40 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



MySQL has a column of type TINYINT but that would not be appropriate. It would not work as you expect. Although TINYINT is 3 digits long, the maximum values are in the range -128 to 127 (or 0 to 255 if unsigned). That's why I think SMALLINT is your best choice.