i created a table “composers” VALUES (name VARCHAR(30), birth YEAR(4), death YEAR(4), city VARCHAR(30), country VARCHAR(30)). then i INSERT INTO composers VALUES (‘BACH Johann Sebastian’,1685,1750,’Eisenach’,’Germany’);. it returns 2 errors. the years are not between 1901 and 2155.
is there any way of changing this default so i can have an actual year for those columns? cant seem to find anything on the web.
i resorted to just use INTEGER(4) for those columns but would like to use YEAR(4) if it’s possible.
It seems quite clear that this is the only way this type works in the docs.
The
YEAR(4)type only uses 1 byte, and is limited to a range of 256 years. If your use case falls completely within a different 256 year space, you could certainly store them off by a certain amount, and adjust the yourself before writing and after reading, say by -300.Alternatively, use a
SMALLINTorUNSIGNED SMALLINTinstead of a fullINTto use 2 bytes. Not quite the 1 byte that a ‘YEAR(4)’ uses, but less than the 4 bytes for anINT