MySQL TINYINT(1) to BOOL -
what parameter on column's data type do? essentially:
i tried tinyint(1), , seemed held 1 or 0. why doesn't display/store @ least 0-9?
edit: turns out issue not mysql problem rather unexpected behavior cakephp. read answer details. i've kept original question below helpful answers keep making sense.
what i've done:
i created mysql table using command
create table table_name ( ... irrelevant columns transaction_type tinyint(1) not null comment 'identifier 0-5 (for now)' );
and promptly became thoroughly confused, because unable store values other 0 , 1 in transaction_type column.
after research, determined confidently parameter tinyint
(or other integer data type) nothing more display width in characters. understood mean 2 things:
- it should still store entire inserted value, long within tinyint's bounds
- it display 1 character, should able see values 0-9 when select table.
i figure @ least 1 of these assumptions (or understanding of parameter whole) must wrong, because whenever tried insert value larger 1 column, display 1.
i tried:
alter table table_name change transaction_type transaction_type tinyint;
and able insert whatever value wanted. however, though above command changed whole table, previous inserts still had value of 1, making me suspicious stored 1.
am misunderstanding display width, or doing else wrong entirely?
aside: if don't care how integer columns in table, there reason ever supply 1 parameter? i.e. int(11) somehow better int?
a similar question should have been more helpful me: mysql: tinyint (2) vs tinyint(1) - difference?
the clearest source find explaining display width: http://matt.thomm.es/archive/2006/11/28/mysql-integer-columns-and-display-width
in short: depends on how integer 0 filled if zerofill
has been enabled on column.
longer explanation:
the length of integer in sql doesn't change numbers holds (a tinyint
hold -128 127, unsigned tinyint
hold 0-255 etc. no matter length.)
i mysql cheat sheet check sizes.
now - what's actual difference between int
, int(3)
? it's simple. if zerofill
enabled, integer zero-padded length. that's difference.
there's article explaining here.
specifically, copied article (check out! him page-views!)
mysql> select * b; +-------+ | b | +-------+ | 10000 | +-------+ 1 row in set (0.00 sec) mysql> alter table b change b b int(11) zerofill; query ok, 1 row affected (0.00 sec) records: 1 duplicates: 0 warnings: 0 mysql> select * b; +-------------+ | b | +-------------+ | 00000010000 | +-------------+ 1 row in set (0.00 sec)
Comments
Post a Comment