Discuss Need help on what data type should i use in the MySQL Help forum on Dev Shed. Need help on what data type should i use MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 575
Time spent in forums: 1 Week 10 h 47 m
Reputation Power: 382
As you've written it would be a VARCHAR, though you might want to use more than one field for more than one phone number [home/work/cell/etc] for the sake of efficiency if you need to search based on PN.
If you're storing PNs individually then it's really up to you how best to store them. If you need to be storing things like extensions or symbols like + for international dialing then a string type is best, but if it's only ever going to be digits then a numerical type will be more space/computation efficient.
You could also split the phone numbers off to their own table if there's no real upper limit on the number of PNs you want to associate with a given row/person.
Also, 8 characters is very short for any sort of name field, and I don't know why you'd want it to be CHAR instead of VARCHAR.
Posts: 4
Time spent in forums: 3 sec
Reputation Power: 0
Quote:
Originally Posted by swillis16
1. You can store all three numbers as a varchar.
2. You can create three phone number colums in the database with each being a varchar.
Either one is fine, but with option 1 you may have to split the string at the commas if you are making an application using the database.
One of the phone number data i have to save consist of 13 numbers with 6 different numbers. Meaning i have to use varchar(84). Is there any other better method? Cheers.
Posts: 4
Time spent in forums: 3 sec
Reputation Power: 0
Quote:
Originally Posted by fubes2000
As you've written it would be a VARCHAR, though you might want to use more than one field for more than one phone number [home/work/cell/etc] for the sake of efficiency if you need to search based on PN.
If you're storing PNs individually then it's really up to you how best to store them. If you need to be storing things like extensions or symbols like + for international dialing then a string type is best, but if it's only ever going to be digits then a numerical type will be more space/computation efficient.
You could also split the phone numbers off to their own table if there's no real upper limit on the number of PNs you want to associate with a given row/person.
Also, 8 characters is very short for any sort of name field, and I don't know why you'd want it to be CHAR instead of VARCHAR.
Thanks for the suggestion. Yep, that was juz an example, my data type for name is varchar(30). Cheers
Posts: 6,459
Time spent in forums: 1 Month 2 Weeks 4 Days 2 h 44 m 4 sec
Reputation Power: 6144
Quote:
One of the phone number data i have to save consist of 13 numbers with 6 different numbers. Meaning i have to use varchar(84). Is there any other better method? Cheers.
Yes, separating them by commas and storing them all in the same field is one of the worst methods possible.
Having multiple fields (phone_number1, phone_number2, etc.) in your table is only marginally better.
The best method is one fubes2000 recommended:
Quote:
You could also split the phone numbers off to their own table if there's no real upper limit on the number of PNs you want to associate with a given row/person.
It gives you more flexibility and is far easier to query.
Phone numbers have a lot of possible variations, it is pretty much always best to store them as varchar.