Solved

integer-questions

Posted on 2004-11-02
473 Views
Last Modified: 2008-02-26
http://dev.mysql.com/doc/mysql/en/Numeric_type_overview.html

In this overview you can see for example:
TINYINT = 0 - 255 (unsigned)
SMALLINT = 0 - 65535 (unsigned)
MEDIUMINT = 0 - 16777215 (unsigned)

Now in my database (MySQL) I use for example
SMALLINT(3) for numbers from 0 -> 999. But lately I saw I could use SMALLINT(1) as well for that...

Can someone clarify this?
0
Question by:G00fy
    5 Comments
     
    LVL 9

    Expert Comment

    by:AlanJDM
    "But lately I saw I could use SMALLINT(1) as well for that"

    Where did you see that?


    Alan

    0
     

    Author Comment

    by:G00fy
    In my database... I was using values of lets say '2300', normally I would use like SMALLINT(4) for that, but lately I saw that when I use SMALLINT(1) as well...
    0
     
    LVL 9

    Expert Comment

    by:AlanJDM
    I will be curious to see if anyone has any insight to this as well. I am not sure of the inner workings of MySQL but some logic and some basic math skills would tell you that 2300 can't be stored in one byte. My guess would be that the '1' doesn't represent what it appears to represent.



    Alan
    0
     

    Author Comment

    by:G00fy
    My best guess is that the 1 means like (smallint = 2 bytes), so that it would mean 2bytes x 1
    And then it is correct. If this is true however, then I am very stupid as all my indexes on my database are like INT(10) :-)
    0
     

    Accepted Solution

    by:
    http://dev.mysql.com/doc/mysql/en/Numeric_types.html


    Another extension is supported by MySQL for optionally specifying the display width of an integer value in parentheses following the base keyword for the type (for example, INT(4)). This optional display width specification is used to left-pad the display of values having a width less than the width specified for the column.

    The display width does not constrain the range of values that can be stored in the column, nor the number of digits that will be displayed for values having a width exceeding that specified for the column.


    Meaning:
    ---------------
    If you specify INT(4), then the storage size will be INT anyway. The 4 just means if you want to display it, it can be zero-padded to that length. (with other words: it doesn't matter that you specify 4 or 1 if you don't concern yourself with display, fe. if only using it in PHP).


    Greetz
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now