Forum Moderators: open

Message Too Old, No Replies

When should you used "Unsigned"

Mysql

         

neophyte

4:21 am on Apr 3, 2006 (gmt 0)

10+ Year Member



Hi All -

Please forgive me what I believe is a basic question, but I'm posting this in the light of "doing things right".

So, question is: when a field is defined as a int or float or decimal (or I suppose any other numeric data types) when should you specify the field as "unsigned"?

I've read online that "unsigned" offers some speed or size advantages to these fields, but I'm looking for recommondations regarding "best practices".

Also (and as a minor aside) what do people feel about the decimal or float datatype when you've got to store something like "12.25" to, say "122.75". I thought that float was the preferred method, but after checking the MYSQL manual, it indicated that decimal would be a better choice from a precision standpoint. It really doesn't matter to me, just as long as the specified precision was there...and that I could do calculations on the number if needed.

Thanks to all in advance,

Neophyte

physics

5:24 am on Apr 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suppose a best practice is that if you never will have negative values in a field (such as price) then use unsigned. Be careful that you want this though. Sometimes I'll use -999 to denote an error in the price for example.