SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What exactly does SIGNED and UNSIGNED stand for?

    Hello!

    Could someone explain what SIGNED and UNSIGNED in conjunction with MySQL means?

    I tried to get the grasp but failed

    Thanks a lot in advance!

  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SIGNED means that a numeric value can be positive or negative. UNSIGNED is only positive.
    as all values take up a certain ammount of space, you should choose what you need: if it's only positive values you want, go for UNSIGNED, as the space is completely available for positive numbers (e.g. INT can taje values up to 65536. if it's SIGNED, you can store any value from 0 to 65535. if it's UNSIGNED, from -32768 to 32767). hope this makes it clear (and hope it's correct as well )
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And therefore unsigned kinda gives twice as much space as signed. If I remember correctly, it's to do with a bit out of the byte being used to indicate the sign of the number.

  4. #4
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That explains a bit, but how can i tell a field in MySQL to be SIGNED or UNSIGNED?

    [It is funny, the further i delve into MySQL the more complicated it gets and the more one needs to know about it. I think it is about time i go out and buy a good book )

  5. #5
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it when you create the table like this:

    CREATE TABLE `tablename` (`fieldname` INT UNSIGNED NOT NULL )

    You can also alter the field to add it of course

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to a more appropriate forum

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes thank you i noticed, sorry bout that, it is sort of a bad habbit to post MySQL related questions into the PHP Forum

    Just another quick question.
    Am i assuming correct that all fields are automatically SIGNED then?

  8. #8
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah.

  9. #9
    SitePoint Addict delpino's Avatar
    Join Date
    Nov 2001
    Location
    London
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about "unsigned zerofill".. and what is the default if you do not choose signed or unsigned?

  10. #10
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Note that if you specify ZEROFILL for a column, MySQL will automatically add the UNSIGNED attribute to the column.
    from the mysql docs here -> http://www.mysql.com/doc/C/o/Column_types.html

    and the default is SIGNED as said just above your post

    btw, the documentation at www.mysql.com/doc helps a lot if you've any basic questions ... keep in mind though we're not discouraging you from posting should you have any questions at all, just pointing out a good resource

    i'm not newbie-unfriendly, unlike some people at a certain Perl community (not the one here!)


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
  •