MySQL pre version 5.0 was very lax in it’s management of valid data. It was easy for data integrity to be abused if you knew how. The most common examples were truncations and silent conversions that if not understood could provide a serious data integrity issue.
In version 5.0, the introduction of SQL_MODE solved this problem. We will look at one example of how SQL_MODE can be enabled to provided improved data integrity.
You want to store the individual RGB (red/green/blue) decimal values of colors in a table. Each of these has a range from 0 to 255. You read that you can store 255 values in a TINYINT Integer data type, so you create a table like:
DROP TABLE IF EXISTS color_to_decimal; CREATE TABLE color_to_decimal( name VARCHAR(20) NOT NULL PRIMARY KEY, red TINYINT NOT NULL, green TINYINT NOT NULL, blue TINYINT NOT NULL); …[Read more]