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!
| SitePoint Sponsor |




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!
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



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.




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)
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
Moved to a more appropriate forum
Sean![]()
Harry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature




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?



Yeah.


what about "unsigned zerofill".. and what is the default if you do not choose signed or unsigned?
from the mysql docs here -> http://www.mysql.com/doc/C/o/Column_types.htmlNote that if you specify ZEROFILL for a column, MySQL will automatically add the UNSIGNED attribute to the column.
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