SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple - mysql primary key

    When declare a key in table, should I use 'unsigned' or should I removed it? Thanks.

    id int unsigned NOT NULL PRIMARY KEY auto_increment

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it depends on the type of data you intend to store in the field

    an "unsigned" integer will only hold values of 0 or greater - so if the field is only ever going to contain positive integers the field will be able to store a wider range

    a "signed" integer allows storage of both negative and positive numbers

    check out the mysql docs to look up the actual range in each case for each type of integer

    in this case the signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.

  3. #3
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm thinking about storing maximum number of rows in database. So that means if I had 'unsigned' declared in the primary key, I can store more rows in a table ...


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
  •