volitics — 2012-06-13T13:13:30-04:00 — #1
I am working on a MySQL database table for baseball game scores.
Does anybody know why I need to use one of the integer column types to store numbers?
If I do a SELECT clause and apply the gettype() function to numbers extracted from an integer column types they come out as type "string" - not type "integer."
I am trying to get an integer column to have a default value of empty. However, the table automatically inserts a "0" in an empty column. It displays on the page as a "0" when there should be a blank space there (before the games are played it needs to be an empty space since there's not yet a score).
If I use a varchar column type it will default to an empty cell. If I extract the number from the varchar column type using a select function is also comes out as type "string."
Basically, varchar does what I need with a number. The integer column type does not.
I am trying to figure out if I use varchar column types for the numerical scores, instead of the integer type, will it cause problems later on?
I would appreciate any information that someone might have.
r937 — 2012-06-13T13:22:38-04:00 — #2
because that's the best datatype for whole numbers (like scores... unless you can be awarded a half of a point, for example)
that would be a problem with whatever language this "gettype" function belongs to
presumably it's php, in which case you should ask that question in the php forum
you need to declare the column with NULL instead of NOT NULL
in summary, don't use VARCHAR, use SMALLINT (unless your scores can exceed 32768, then use INTEGER)
volitics — 2012-06-13T19:33:34-04:00 — #3
Thanks for responding to my question. NULL is what I needed to know. I set the column default setting to NULL and it eliminated the zeros.
mittineague — 2014-09-22T23:39:04-04:00 — #4
This topic is now archived. It is frozen and cannot be changed in any way.