SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    What data type should be used for an phone number?

    I'm setting up a MySQL table and I imagine an URL and email data type would be VARCHAR 50, but I'm not sure about a phone number. Because it's made of numbers, TINYINT? There won't be any arithmetic performed on the numbers, so TINYTEXT would be fine?
    Steve Husting

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by StevenHu View Post
    There won't be any arithmetic performed on the numbers, so TINYTEXT would be fine?
    i love the premise, and i agree with it -- when was the last time you were asked to find the AVG(phonenumber) or SUM(phonenumber)?

    but the conclusion is false... since there won't be any arithmetic performed on the numbers, use VARCHAR

    (besides, TINYINT isn't big enough)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks!
    Steve Husting

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,819
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    varchar 50 is a bit small for urls or email addresses - a domain name can be up to 63 characters long by itself and the part of an email address before the @ can be up to 255 characters long (but is unlikely to be anywhere near that big) so a varchar 255 is probably the most appropriate value (since it doesn't take any more space if the values all turn out to be less than 50 and greater than 255 is possible but so unlikely that it isn't worth catering for.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you, Stephen; that's helpful! I'll make the change.
    Steve Husting


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •