SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Field Size

  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    Russia
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Field Size

    I noticed some interesting thing
    When I create some field lets say of int type its size supposed to be 4 bytes. Like this

    Alter table tbl_countries add country_id INT

    Then I looked into the table using MySQL-Front and was amaized to find out that the field has a length of 11. From where is the addon of 7 bytes ?

    If i force the size and change it to 4 it works perfectly. And the maximum value that can be in both cases is 4294967295 (unsigned) but why mysql adds those 7 bytes?

    By the way the same thing is happening with tinyint which by default comes with size of 4 instead of 1.

    If anyone can explain this I would be thankful.

    ----

    My second question is about alter table
    I want to add pack_keys=1 to some of my read only accessed tables which have numeric indexes, what is the correct alter table statement to add this option.

    Thanks

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think 11 means 11 positions in the number, which is equal to 4 bytes (max value 2147483648, and the 11th position is for "-", if negative)
    Correct?

  3. #3
    SitePoint Member
    Join Date
    May 2003
    Location
    Russia
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm probably so but then if I change this possition to 4 I still can enter maximum value for integer. Then for what those positions used ?

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySql docs:
    "INT[(M)] [UNSIGNED] [ZEROFILL]
    A normal-size integer.
    ... M Indicates the maximum display size."

    Don't know why you would want to use 4 bytes, but only display numbers up to, for example, 9999?
    Mysterious...


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
  •